IOS开发之UISearchBar自定义外观
@interface MySearchBar : UISearchBar
- (void)layoutSubviews;
@end
MySearchBar.m如下:
#import "MySearchBar.h"
@implementation MySearchBar
- (void)layoutSubviews {
UITextField *searchField;
NSUInteger numViews = [self.subviews count];
for(int i = 0; i < numViews; i++) {
if([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]])
{ //conform?
searchField = [self.subviews objectAtIndex:i];
}
}
if(!(searchField == nil)) {
searchField.textColor = [UIColor redColor];
[searchField setBorderStyle:UITextBorderStyleRoundedRect];
UIImage *image = [UIImage imageNamed: @"出发位置.png"];
UIImageView *iView = [[UIImageView alloc] initWithImage:image];
searchField.leftView = iView;
}
[super layoutSubviews];
}
@end
应用:
MySearchBar *searchBar = [MySearchBar alloc] initWithRct:CGRectMark(10, 10 ,100,30)];
searchBar.backgroundColor = [UIColor clearColor]; //修改搜索框背景
searchBar.showsScopeBar = NO;
[[searchBar.subviews objectAtIndex:0]removeFromSuperview]; //去掉搜索框背景
for (UIView *subview in searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subview removeFromSuperview];
break;
}
}
// UIView *baView = [[UIView alloc] init];
// baView.backgroundColor = [UIColor clearColor];
//
// [searchBar insertSubview:baView atIndex:1];
最新文章
- swiper的初步使用
- Android开发之JavaMail发送邮件(用户反馈)
- Linux下错误的捕获:全局变量errno和strerror()
- 利用奇异值分解(SVD)简化数据
- java入门 第一季4
- sina发现并不会去导入qq使用的
- DOJO官方API翻译或解读-dojo/store (自定制存储器)
- C/C++中的可变参函数
- applicationContext.xml详解
- ContentMode 几个属性
- 安卓开发:简单的登陆跳转_APK实现直接跳转到本CSDN博客
- Java集合之Stack
- Java集合与泛型中的几个陷阱,你掉进了几个?
- 为 pip install 设置 socks5 代理
- .net里的ref、out、params参数。
- 十一、移植优化---CONFIG 优化进 menuconfig(2)
- 使用命令行登陆数据库配置文件修改 解决ora12528
- ci框架memcached使用
- 4G模块luci的配置及重连脚本
- 七牛云存储 qiniu 域名 回收 文件上传 备份 下载 MD