查了不少资料,都不太全,自己查看了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的用法的更多相关文章

  1. UISearchController 的用法[点击搜索框,自动到顶部]

    //在ViewDidLoad里面如下代码 self.searchViewController = [[UISearchController alloc]initWithSearchResultsCon ...

  2. 【原】iOS优秀开源项目总结

    网上此类帖子博客不少,不过自己没整理过的东西始终是别人,现开此贴加以总结,持续更新!站在巨人的肩膀上才能站得高看得远. 第一部分:UI类 1.毛玻璃模糊效果 RNFrostedSidebar 一个iO ...

  3. iOS之搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)

    在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...

  4. 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar + UISearchDisplayController)

    1.searchResultsUpdater:设置显示搜索结果的控制器 ? 1     _mySearchController.searchResultsUpdater = self; 2.dimsB ...

  5. UISearchController的使用。(iOS8+)

    这种方法早就发现了,不过一致没用,今天拿过来用,发现了一些问题. 1.这个东西和表视图结合使用很方便,首先,创建新的工程,将表视图控制器作为工程的根视图,并且添加一个导航(当然,你可以不这样做,但是你 ...

  6. iOS --- 搜索框UISearchController的使用(iOS8.0以后替代UISearchBar+display)

    在iOS 8.0以上版本中, 我们可以使用UISearchController来非常方便地在UITableView中添加搜索框. 而在之前版本中, 我们还是必须使用UISearchBar + UISe ...

  7. CoreLocation在iOS8上用法的变化

    1.在使用CoreLocation前需要调用如下函数[iOS8专用]: iOS8对定位进行了一些修改,其中包括定位授权的方法,CLLocationManager增加了下面的两个方法: (1)始终允许访 ...

  8. Swift - 使用UISearchController实现带搜索栏的表格

    我原来写过一篇文章“Swift - 带结果列表的搜索条(UISearchDisplayController)的用法”,当时是使用UISearchDisplayController来实现带有搜索功能的列 ...

  9. Swift - 带结果列表的搜索条(UISearchDisplayController)的用法

    (注:自iOS8起,苹果便废弃UISearchDisplayController的使用,改为使用UISearchController来实现类似功能,可参考我的另一篇文章“Swift - 使用UISea ...

随机推荐

  1. The connection to adb is down, and a severe error has occured.(DDMS中没有真机)

    最近老是出现真机用着用着就掉线了,在DDMS中看不到,运行项目出现选择运行机器中也没有,360助手连接电脑OK,任务管理器中没有adb.exe,重启eclipse不行,只能每次重启电脑.按照http: ...

  2. 整合ssh model $$_javassist_13 cannot be cast to javassist.util.proxy.Proxy

    经goole stackoverflow 发现是 javassit 包冲突 项目使用的是maven 检查依赖包

  3. 关于全局唯一ID生成方法

    引:最近业务开发过程中需要涉及到全局唯一ID生成.之前零零总总的收集过一些相关资料,特此整理以便后用 本博客已经迁移至:http://cenalulu.github.io/ 本篇博文已经迁移,阅读全文 ...

  4. Tomcat Clustering - A Step By Step Guide --转载

    Tomcat Clustering - A Step By Step Guide Apache Tomcat is a great performer on its own, but if you'r ...

  5. 【JVM学习笔记一】JVM内存分布

    Overview 学习JVM首先需要了解一下JVM管理的内存是如何分布的,在看了<深入理解Java虚拟机>和一些博文之后,我准备自己记录一下学习的过程. 下图是JVM中运行时数据区的大致示 ...

  6. Love

    愿这段代码陪我走过此生,献给我最爱的榨菜. /** *@Description:<p>我爱榨菜</p> *@author 王旭 *@time 2016年4月25日 下午7:58 ...

  7. 小printf的故事(未完待续)

    小printf的故事 这篇文章的原文来自:英文原文作者仿照<小王子>中的情节,生动有趣的阐述了小printf从编程小白到专家的成长历程.这是我第一次尝试翻译文章,肯定有很多不足之处,情不要 ...

  8. css命名那些事儿

    根据目前彩票行业的公司进行css命名的层级解析,此次选择了网易彩票,QQ彩票,澳客彩票网,中国竞彩网,500.com,彩票365,新浪彩票,新浪爱彩,凤凰彩票,淘宝彩票的首页进行css命名的采集和分析 ...

  9. Mysql查询大表出现的一个错误

    第一次测试执行下面的语句时发生如下错误:bigdata里面有100万条数据 mysql> select count(*) from (select distinct(id) from bigda ...

  10. BAT及各大互联网公司前端笔试面试题--Html,Css篇

    注意 转载须保留原文链接(http://www.cnblogs.com/wzhiq896/p/5931347.html )作者:wangwen896 整理分享出来希望更多的前端er共同进步吧,不仅适用 ...