zoukankan      html  css  js  c++  java
  • 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. 查看效果:

  • 相关阅读:
    面向对象---工厂模式
    [转]Caffe 安装配置(CentOS + 无GPU)
    [转]Centos6.5+CUDA6.5+caffe安装配置及可能遇到问题解答
    [转]Caffe安装过程记录(CentOS,无独立显卡,无GPU)
    [转]LIBRARY_PATH和LD_LIBRARY_PATH环境变量的区别
    [转]centos 6.5安装caffe
    [转]CentOS编译安装GIMP
    [转]Snappy压缩库安装和使用之一
    [转]拍照怎么搜题?(下)
    [转]拍照怎么搜题?(上)
  • 原文地址:https://www.cnblogs.com/jgCho/p/5229979.html
Copyright © 2011-2022 走看看