UISearchBar/UISearchDisplayContr

作者: 叶LOveFIsh | 来源:发表于2017-03-23 15:49 被阅读37次

    使用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/UISearchDisplayContr

        本文链接:https://www.haomeiwen.com/subject/xtzznttx.html