- (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;
}
}
}
}