我使用以下代码设置搜索控制器
_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];
在查看视图层次结构时,我发现了一个我从未添加的视图
我尝试删除此视图,但我无法删除,因为backgroundview
没有任何子视图
NSInteger count = backgroundview.subviews;
for (UIView *sub in backgroundview.subviews) {
NSLog(@"%@", NSStringFromClass(sub.class));// don't have any subView
}
如何删除此特定视图?