使用UISearchController的时候,有时候在激活状态

2017-04-14  本文已影响109人  落寒z

使用UISearchController的时候,有时候在激活状态显示上偏移过多的情况处理,设置下列代码

 self.definesPresentationContext = YES;
    
self.extendedLayoutIncludesOpaqueBars  = YES;

设置UISearchController ,并自定义背景,激活状态背景颜色改变

- (UISearchController *)searchController {
    if (_searchController == nil) {
        _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
        _searchController.searchResultsUpdater = self;
        _searchController.searchBar.placeholder = @"姓名/工号/电话/部门";
        _searchController.hidesNavigationBarDuringPresentation = YES;
        _searchController.searchBar.delegate = self;
        _searchController.searchBar.backgroundImage = [UIImage imageWithColor:AB_Color_f2f2f2 size:_searchController.searchBar.size];
        
        CGSize size = CGSizeMake(_searchController.searchBar.size.width, _searchController.searchBar.size.height + 20);
        [_searchController.searchBar setBackgroundImage:[UIImage imageWithColor:AB_Color_f3f3f3 size:size] forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];
        
        [_searchController.searchBar sizeToFit];
    }
    return _searchController;
}

上一篇下一篇

猜你喜欢

热点阅读