UISeatchBar
1、修改UISearchBar的背景颜色
UISearchBar是由两个subView组成的,一个是UISearchBarBackGround,另一个是UITextField. 要IB中没有直接操作背景的属性。方法是直接将 UISearchBarBackGround移去
- seachBar=[[UISearchBar alloc] init];
- seachBar.backgroundColor=[UIColor clearColor];
- for (UIView *subview in seachBar.subviews)
- {
- if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
- {
- [subview removeFromSuperview];
- break;
- }
- }
第二种解决的方法:
- [[searchbar.subviews objectAtIndex:0]removeFromSuperview];
2、
UISearchBar* m_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 44, 320, 41)];
m_searchBar.delegate = self;
m_searchBar.barStyle = UIBarStyleBlackTranslucent;
m_searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
m_searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
m_searchBar.placeholder = _(@"Search");
m_searchBar.keyboardType = UIKeyboardTypeDefault;
//为UISearchBar添加背景图片
UIView *segment = [m_searchBar.subviews objectAtIndex:0];
UIImageView *bgImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Images/search_bar_bg.png"]]; [segment addSubview: bgImage];
//<---背景图片
[self.view addSubview:m_searchBar];
[m_searchBar release];
3:取消UISearchBar调用的键盘
- [searchBar resignFirstResponder];
添加UISearchBar的两种方法:
代码
- UISearchBar *mySearchBar = [[UISearchBar alloc]
- initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 45)];
- mySearchBar.delegate = self;
- mySearchBar.showsCancelButton = NO;
- mySearchBar.barStyle=UIBarStyleDefault;
- mySearchBar.placeholder=@"Enter Name or Categary"; //输入框中原始的文字
- mySearchBar.keyboardType=UIKeyboardTypeNamePhonePad;
- [self.view addSubview:mySearchBar];
- [mySearchBar release];
3.在 tableview上添加:
代码
//add Table
UITableView *myBeaconsTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-40) style:UITableViewStylePlain];
myBeaconsTableView.backgroundColor = [UIColor whiteColor];
myBeaconsTableView.delegate=self;
myBeaconsTableView.dataSource=self;
[myBeaconsTableView setRowHeight:40];
// Add searchbar
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, 40)];
searchBar.placeholder=@"Enter Name";
searchBar.delegate = self;
myBeaconsTableView.tableHeaderView = searchBar;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
[searchBar release];
[self.view addSubview:myBeaconsTableView];
[myBeaconsTableView release];
4.删除搜索框背景
[[mSearchBar.subviewsobjectAtIndex:0]removeFromSuperview];
// 删除searchBar输入框的背景
for (UIView* subview in mSearchBar.subviews) {
if ([subview isKindOfClass:[UITextField class]]) {
UITextField * searchField = (UITextField*)subview;
searchField.leftView=nil;//隐藏搜索小图标
[searchField setBackground:nil];
[searchField setBorderStyle:UITextBorderStyleNone];
break;
}
}
转载于:https://www.cnblogs.com/Cristen/archive/2012/11/20/2779155.html
UISeatchBar相关推荐
最新文章
- python str byte编码_Python3中内置类型bytes和str用法及byte和string之间各种编码转换 问题...
- 【河南省多校脸萌第六场 E】LLM找对象
- RandomAccessFile类解析
- 遇到网络问题你是怎么解决的?
- 基于Web的浮动图片墙
- Spark学习笔记:索引分区映射
- python 随机数_python项目实战:实现蒙特卡罗方法,求物体阴影面积
- php5apache2.dll,Apache2.2.8 + PHP5.2.5不能加载php5apache2.dll
- 潜在语义分析(TF-IDF、LSA)
- 基于SSM开发智夫子在线考试系统
- 互联网中几种常用的传输协议
- 利用VB操作目录和文件夹
- 业余10—解决只能打开网页不能打开QQ或视频软件问题
- 终端模拟器编译c语言,开源一个Flutter编写的完整终端模拟器
- Python 去除单色背景
- 40亿美金史上最大 ICO,EOS 疑云
- 给联想拯救者15isk装win7遇到的问题
- 第1090期AI100_机器学习日报(2017-09-12)
- PMI-PMP®远程模考三 正题数
- oracle事务管理器,全能数据库盘问分析器中的事务管理在oracle中的应用.doc
热门文章
- android stub.asinterface是什么意思
- 互联网研发中负载均衡算法一点探索
- EasyDarwin开源音频解码项目EasyAudioDecoder:EasyPlayer Android音频解码库(第二部分,封装解码器接口)...
- 使用FastCoder写缓存单例
- MS的.net源码地址
- 【浸入式英文学习方式】山姆莱萌帮助孩子建立扎实语言功底
- 08-GCD常用方法
- 黄聪:如何用代码设置控制自己网站的网页在360浏览器打开时强制优先使用极速模式,而非兼容模式...
- 远程管理MAC OS
- laravel CURD ORM