iOS 11 UISearchController.searchBar有一个blackColor视图

时间:2018-01-19 02:55:52

标签: ios objective-c ios11 uisearchcontroller

我使用以下代码设置搜索控制器

_searchController = [[UISearchController alloc]initWithSearchResultsController:self.resultVC];
self.definesPresentationContext = YES;
_searchController.dimsBackgroundDuringPresentation = YES;
_searchController.hidesNavigationBarDuringPresentation = YES;
_searchController.searchBar.barTintColor = [UIColor yellowColor];
// 可以通过此种方式可以拿到搜索框,修改搜索框的样式
UITextField *searchField = [_searchController.searchBar valueForKey:@"_searchField"];
searchField.backgroundColor = [UIColor redColor];
searchField.leftView = nil;
searchField.layer.cornerRadius = 4;
searchField.clipsToBounds = YES;
searchField.leftViewMode = UITextFieldViewModeNever;

UIView *backgroundview = searchField.subviews.firstObject;
backgroundview.backgroundColor = [UIColor redColor];

UI

在查看视图层次结构时,我发现了一个我从未添加的视图

the hierarchical chart

我尝试删除此视图,但我无法删除,因为backgroundview没有任何子视图

NSInteger count = backgroundview.subviews;
for (UIView *sub in backgroundview.subviews) {
    NSLog(@"%@", NSStringFromClass(sub.class));// don't have any subView
}

如何删除此特定视图?

0 个答案:

没有答案