关于UISearchBar
iPhone开发之UISearchBar学习是本文要学习的内容,主要介绍了UISearchBar的使用,不多说,我们先来看详细内容。关于UISearchBar的一些问题。
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];
在 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];
小结:iPhone开发之UISearchBar学习的内容介绍完了,希望本文对你有所帮助
copy from http://mobile.51cto.com/iphone-280122.htm
关于UISearchBar的更多相关文章
- iOS 如何自定义UISearchBar 中textField的高度
iOS 如何自定义UISearchBar 中textField的高度 只需设置下边的方法就可以 [_searchBar setSearchFieldBackgroundImage:[UIImage i ...
- iOS之搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)
在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...
- 更改UIsearchbar 的背景和cancel按钮(转)
修改背景 searchbar =[[UISearchBar alloc]initWithFrame:CGRectMake(,KTopBarHeight, , KTopBarHeight)]; sear ...
- UISearchBar控件-让我们来搞定!(转)
转载自:http://blog.sina.com.cn/s/blog_7b9d64af0101dfg8.html 最近用到搜索功能.于是,经过不断的研究,终于,有点懂了. 那就来总结一下吧,好 ...
- iOS开发——UI进阶篇(十九)UISearchBar控件简介
最近用到搜索功能.总结一下 搜索,无疑可以使用UISearchBar控件! 那就先了解一下UISearchBar控件吧! UISearchBar控件就是要为你完成搜索功能的一个专用控件.它集成了很多你 ...
- IOS开发UISearchBar失去第一响应者身份后,取消按钮不执行点击事件的问题
在iOS开发中,使用UISearchBar的时候,当搜索框失去焦点的时候,取消按钮是默认不能点击的,如图按钮的颜色是灰色的: 这是因为此时取消按钮的enabled属性被设置为NO了,那么当我们需要让 ...
- 修改UISearchBar的背景颜色
当你看到这篇博客你就已经发现了用_searchBar.backgroundColor = [UIColor clearColor];来设置UISearchBar的颜色完全没有效果: 并且,有些方法是想 ...
- iOS UISearchBar 设置取消按钮,回收键盘,并修改cancel为“取消”
继承协议: UISearchBarDelegate 在代理方法中设置: #pragma mark --- 搜索框开始编辑 --- - (void)searchBarTextDidBeginEditin ...
- iOS开发之直接使用UISearchBar
iOS开发中经常需要使用SearchBar,我们可以选择使用UISearchBar+UISearchController或者UISearchBar+UISearchDisplayController( ...
- 自定义UISearchBar
先上系统默认的UISearchBar,然后用KVO修改 UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:_topView.boun ...
随机推荐
- 高一python笔记大全(过会考)
最初のプログラム xfは.どちらかの試合(しあい)活動(かつどう)に参加して.a秒(aは整数)を使ったのですが.今あなたがひとつ任務を有:分と秒数を出力するください. a=int(input(&quo ...
- Tomcat 调优技巧
Tomcat 调优技巧:1.Tomcat自身调优: ①采用动静分离节约Tomcat的性能: ②调整Tomcat的线程池: ③调整Tomcat的连接器: ④修改Tomcat的运行模式: ⑤禁用AJP连接 ...
- 关于parseDouble用法
1.JAVA中的compareTo方法和strcmp完全类似,你可以使用 if(greeting.compareTo("help")==0).....或者用s.quals(t)来判 ...
- css解析规则
1.因为css对空格不敏感,因此在每个样式后都要加一个分号,不然会把写在后面的样式当成一个整体来解析,直到遇到分号为止. 2.当遇见不认识的属性或值时,将忽略这个属性,继续解析后面的属性. 3.对于复 ...
- Codeforces Round #275 (Div. 2) B. Friends and Presents 二分+数学
8493833 2014-10-31 08:41:26 njczy2010 B - Friends and Presents G ...
- Python中%r与%s的区别
%r是rper()方法处理的对象 %s是str()方法处理的对象 其实有些情况下,两者处理的结果是一样的,比如说处理数据类型为int型对象: 例如1: print ('I am %d year old ...
- 关于错误Access Violation和too many consecutive exceptions 解决方法
关于错误Access Violation和too many consecutive exceptions 解决方法 “如果DLL中用到了DELPHI的string类型,则DLL和主程序中都需要加上Sh ...
- Educational Codeforces Round 36 (Rated for Div. 2) G. Coprime Arrays
求a_i 在 [1,k]范围内,gcd(a_1,a_2...,a_n) = 1的a的数组个数. F(x)表示gcd(a_1,a_2,...,a_n) = i的a的个数 f(x)表示gcd(a_1,a_ ...
- 校园网、教育网 如何纯粹访问 IPv6 网站避免收费
我国校园网有可靠的 IPv6 网络环境,速度非常快.稳定,并且大多数高校在网络流量计费时不会限制 IPv6 的流量,也就是免费的.然而访问 IPv4 商业网络时,则会收费,并且连接的可靠性一般.可幸的 ...
- 为什么一个目录里放超过十个Mp4文件会导致资源管理器和播放程序变卡变慢?
最近<鬼吹灯之精绝古城>大火,我也下载了剧集放在移动硬盘里. 起初还没事,当剧集超过十个时发现资源管理器变慢了,表现为上方的绿条总是在闪动前进,给文件改名都缓慢无比. 当剧集超过十五个时, ...