iOS8以后 UISearchController的用法
查了不少资料,都不太全,自己查看了apple文档,写了一份代码: 如下(只是界面):
1. 声明属性 @property (nonatomic, strong) UISearchController *searchController;
2. 调用方法: [self searchController];
3. 实现: - (UISearchController *)searchController {
if (!_searchController) {
_searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
// searchBar
_searchController.searchBar.frame = CGRectMake(0, 0, kWidth - 40, 36);
_searchController.searchBar.placeholder = @"搜索";
_searchController.searchBar.barTintColor = [UIColor colorWithRed:1.00f green:0.62f blue:0.45f alpha:1.00f];
// searchBarTextField
UITextField *searchField = nil;
searchField = [[_searchController.searchBar.subviews objectAtIndex:0].subviews lastObject];
searchField.backgroundColor = [UIColor colorWithRed:1.00f green:0.62f blue:0.45f alpha:1.00f];
UIColor *color = [UIColor whiteColor];
searchField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"您也可以输入关键字搜索" attributes:@{NSForegroundColorAttributeName:color}];
_searchController.view = [[UIView alloc] initWithFrame:CGRectMake(20, 352/2, kWidth - 40, 36)];
[_searchController.view addSubview:_searchController.searchBar];
_searchController.view.backgroundColor = [UIColor colorWithRed:1.00f green:0.62f blue:0.45f alpha:1.00f];
[self.tableHeaderView addSubview:self.searchController.view];
}
return _searchController;
}
4. 查看效果:

iOS8以后 UISearchController的用法的更多相关文章
- UISearchController 的用法[点击搜索框,自动到顶部]
//在ViewDidLoad里面如下代码 self.searchViewController = [[UISearchController alloc]initWithSearchResultsCon ...
- 【原】iOS优秀开源项目总结
网上此类帖子博客不少,不过自己没整理过的东西始终是别人,现开此贴加以总结,持续更新!站在巨人的肩膀上才能站得高看得远. 第一部分:UI类 1.毛玻璃模糊效果 RNFrostedSidebar 一个iO ...
- iOS之搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)
在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...
- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UISearchDisplayController)
1.searchResultsUpdater:设置显示搜索结果的控制器 ? 1 _mySearchController.searchResultsUpdater = self; 2.dimsB ...
- UISearchController的使用。(iOS8+)
这种方法早就发现了,不过一致没用,今天拿过来用,发现了一些问题. 1.这个东西和表视图结合使用很方便,首先,创建新的工程,将表视图控制器作为工程的根视图,并且添加一个导航(当然,你可以不这样做,但是你 ...
- iOS --- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)
在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...
- CoreLocation在iOS8上用法的变化
1.在使用CoreLocation前需要调用如下函数[iOS8专用]: iOS8对定位进行了一些修改,其中包括定位授权的方法,CLLocationManager增加了下面的两个方法: (1)始终允许访 ...
- Swift - 使用UISearchController实现带搜索栏的表格
我原来写过一篇文章“Swift - 带结果列表的搜索条(UISearchDisplayController)的用法”,当时是使用UISearchDisplayController来实现带有搜索功能的列 ...
- Swift - 带结果列表的搜索条(UISearchDisplayController)的用法
(注:自iOS8起,苹果便废弃UISearchDisplayController的使用,改为使用UISearchController来实现类似功能,可参考我的另一篇文章“Swift - 使用UISea ...
随机推荐
- IIS6.0启动网站ManagedPipelineHandler异常
处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler” 开发web项目需要安装IIS,当安装完以后,web程 ...
- 随着ScrollView的滑动,渐渐的执行动画View
今天是实现了一个小功能的东西.看看效果图: 实现方式: 1.自定义ScrollView 复写onScrollChange方法,来计算滑动的位置. 2.自定义接口,通过接口来在ScrollView中 ...
- [OpenCV] Image Processing - Image Elementary Knowledge
"没有坚实的理论基础,实践只会浅尝于表面." 这是两本打基础的书,没系统学过的话,怎么好意思说自己会CV. 该领域,兴军亮 这个名字屡次出现,看来是计算机视觉领域国内的年轻才俊,向 ...
- [Python] Symbol Review
From:http://learnpythonthehardway.org/book/ex37.html 1. with X as Y: pass 1.1 yield 2. exec 2.1 name ...
- linux shell 流程控制(条件if,循环【for,while】,选择【case】语句实例 --转载
http://www.cnblogs.com/chengmo/archive/2010/10/14/1851434.html nux shell有一套自己的流程控制语句,其中包括条件语句(if),循环 ...
- Socket.IO – 基于 WebSocket 构建跨浏览器的实时应用
Socket.IO 是一个功能非常强大的框架,能够帮助你构建基于 WebSocket 的跨浏览器的实时应用.支持主流浏览器,多种平台,多种传输模式,还可以集合 Exppress 框架构建各种功能复杂 ...
- LeetCode——Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...
- 如何用参数化SQL语句污染你的计划缓存
你的SQL语句的参数化总是个好想法.使用参数化SQL语句你不会污染你的计划缓存——错!!!在这篇文章里我想向你展示下用参数化SQL语句就可以污染你的计划缓存,这是非常简单的! ADO.NET-AddW ...
- ASP.NET 文件上传类 简单好用
调用: UploadFile uf = new UploadFile(); /*可选参数*/ uf.SetIsUseOldFileName(true);//是否使用原始文件名作为新文件的文件名(默认: ...
- Android程序ToDoList
本文的目的是创建一个简单的ToDoList列表. 这个应用的功能是记录我的代办事项,简单到不需要本地存储,所有的代办事项都只是存储在内存中,就是只有程序打开的时候可以增加查看代办事项,当程序关闭的时候 ...