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;

}

}

}

}

亲测可用~~~

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容