MySearchBar.h如下:

@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];

最新文章

  1. swiper的初步使用
  2. Android开发之JavaMail发送邮件(用户反馈)
  3. Linux下错误的捕获:全局变量errno和strerror()
  4. 利用奇异值分解(SVD)简化数据
  5. java入门 第一季4
  6. sina发现并不会去导入qq使用的
  7. DOJO官方API翻译或解读-dojo/store (自定制存储器)
  8. C/C++中的可变参函数
  9. applicationContext.xml详解
  10. ContentMode 几个属性
  11. 安卓开发:简单的登陆跳转_APK实现直接跳转到本CSDN博客
  12. Java集合之Stack
  13. Java集合与泛型中的几个陷阱,你掉进了几个?
  14. 为 pip install 设置 socks5 代理
  15. .net里的ref、out、params参数。
  16. 十一、移植优化---CONFIG 优化进 menuconfig(2)
  17. 使用命令行登陆数据库配置文件修改 解决ora12528
  18. ci框架memcached使用
  19. 4G模块luci的配置及重连脚本
  20. 七牛云存储 qiniu 域名 回收 文件上传 备份 下载 MD

热门文章

  1. GIT → 02:Git和Svn比较
  2. 类的加载classload和类对象的生成
  3. Ionic.Zip
  4. AndroidStudio离线打包MUI集成JPush极光推送并在java后端管理推送
  5. 电脑上做的ppt拿到别的电脑或手机上播放的时候字体错位的解决方法
  6. Java.控制层.响应工具类.
  7. php is_null、empty、isset的区别
  8. 阿里云linux服务器到期后续费,网站打不开解决方法之一
  9. 盘点Apache毕业的11个顶级项目
  10. 纯CSS3实现Metro Icon