关于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 ...
随机推荐
- Java中NIO、BIO、AIO相关概念及应用场景
1.同步阻塞IO(JAVA BIO):同步并阻塞,服务器实现模式为一个连接一个线程,即客户端有连接请求时,服务器端就需要启动一个线程进行处理,如果这个连接不做任何事情会造成不必要的线程开销,当然可以通 ...
- cf487C Prefix Product Sequence
Consider a sequence [a1, a2, ... , an]. Define its prefix product sequence . Now given n, find a per ...
- Spring JdbcTemplate 与 事务管理 学习
Spring的JDBC框架能够承担资源管理和异常处理的工作,从而简化我们的JDBC代码, 让我们只需编写从数据库读写数据所必需的代码.Spring把数据访问的样板代码隐藏到模板类之下, 结合Sprin ...
- PHP实现当前文件夹下所有文件和文件夹的遍历
<?php function myScandir($dir){ static $flag=''; //设置缩进显示格式 $files = scandir($dir);//读取当前文件夹的文件 $ ...
- Codevs 5564 陶陶摘苹果2
5564 陶陶摘苹果2 时间限制: 1 s 空间限制: 16000 KB 题目等级 : 白银 Silver 题目描述 Description 陶陶已经够高摘到所有苹果了,但是他力量有限,最大承受质量为 ...
- javascript实现数据结构----栈
//栈是一种遵从后进先出原则的有序集合. //新添加的或待删除的元素都保存在栈的末尾,称作栈顶,另一端就叫栈底 //在栈里,新元素都靠近栈顶,旧元素都叫做栈底 function Stack(){ va ...
- hdu 4951
Multiplication table Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- msp430项目编程41
msp430综合项目---红外遥控直流电机调速系统41
- Codeforces 667D World Tour【最短路+枚举】
垃圾csdn,累感不爱! 题目链接: http://codeforces.com/contest/667/problem/D 题意: 在有向图中找到四个点,使得这些点之间的最短距离之和最大. 分析: ...
- java.nio.ByteBuffer 以及flip,clear及rewind区别
Buffer 类 定义了一个可以线性存放primitive type数据的容器接口.Buffer主要包含了与类型(byte, char…)无关的功能. 值得注意的是Buffer及其子类都不是线程安全的 ...