UISearchBar/UISearchDisplayController阴影遮盖背景色修改

使用UISearchBar时,开始进行搜索,搜索框向上弹开始搜索,搜索框下方的阴影区域及键盘弹出,产品要求对阴影视图定制修改透明度为0.15,针对这个需求进行的开发。

核心代码:

// _searchBar为实例化的UISearchBar对象

UISearchDisplayController * _searchBarController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];

[_searchBarController setSearchResultsDataSource:self];

[_searchBarController setSearchResultsDelegate:self];

[_searchBarController setDelegate:self];

//实现代理方法----切记一定是在DidBeginSearch
- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller

{

UIView *superV = controller.searchResultsTableView.superview;

UIView *superSuperV = superV.superview;

for (UIView *view in superSuperV.subviews) {

for (UIView *getView in view.subviews) {

if ([getView isKindOfClass:[NSClassFromString(@"_UISearchDisplayControllerDimmingView") class]])

{

getView.alpha = 0.15;

}

}

}

}

亲测可用~~~

你可能感兴趣的:(UISearchBar/UISearchDisplayController阴影遮盖背景色修改)