iOS开发之不会就百度: UISearchController 修改外观

- (void)initSearchController{

    

    _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];

    _searchController.searchBar.tintColor = LogoColor;

    _searchController.searchBar.barTintColor = [UIColor whiteColor];

    _searchController.searchResultsUpdater = self;

    //是否显示遮罩

    _searchController.dimsBackgroundDuringPresentation = NO;

    //不让搜索的时候隐藏navigationBar

    _searchController.hidesNavigationBarDuringPresentation = NO;

    //显示搜索结构的按钮

    _searchController.searchBar.showsSearchResultsButton = NO;

    _searchController.searchBar.placeholder = @"输入****";

    _searchController.searchBar.delegate = self;

    [_searchController.searchBar sizeToFit];

    

    //想修改得设置为YES 或者 在info 里修改Localization native development region 属性为china就是修改改app所有的系统文字为中文 

    _searchController.searchBar.showsCancelButton = YES;

    for(UIView *search in _searchController.searchBar.subviews){

        

        NSMutableArray *array = [search valueForKeyPath:@"subviewCache"];

        

        NSLog(@"array %@",array);

        

        for (id subview in array) {

            

            if ([subview isKindOfClass:[UIButton class]]) {

                

                UIButton *cancel = (UIButton *)subview;

                cancel.titleLabel.font = [UIFont systemFontOfSize:14];

                [cancel setTitle:@"自定义" forState:UIControlStateNormal];

                [cancel setTitleColor:LogoColor forState:UIControlStateNormal];

            }

            

    //修改输入框外观

            if ([subview isKindOfClass:[UITextField class]]) {

                

                UITextField *textField = (UITextField *)subview;

                textField.layer.borderWidth = 0.5f;

                textField.layer.borderColor = [LineColor221 CGColor];

                textField.layer.cornerRadius = 5.0f;

                textField.layer.masksToBounds = YES;

            }

        }

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值