UISearchBar没有在ios 8中的UIStatusBar下扩展其背景颜色

我有一个UIViewController,里面有一个UICollectionView,顶部有一个UISearchBar.问题是,当我点击我的搜索栏并隐藏导航栏时,搜索栏背景颜色不会在状态栏下延伸.

以下是我如何设置UISearchBar和UISearchController:

UINavigationController *searchResultsController = [[self storyboard] instantiateViewControllerWithIdentifier:[ADC_SEARCH_RESULTS_CONTROLLER_IDENT copy]];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44.0);
[self.view insertSubview:self.searchController.searchBar belowSubview:self.navigationController.navigationBar];
self.definesPresentationContext = YES;
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;
SuggestionResultsTVC *vc = (SuggestionResultsTVC *)searchResultsController.topViewController;
vc.tableView.contentInset = UIEdgeInsetsMake(0.0f, 0.f, 0.f, 0.f);
self.searchController.searchBar.clipsToBounds = YES;

以下是解除搜索栏时UIViewController的屏幕截图:
http://s4.postimg.org/x0rncg5e5/Screen_Shot_2015_09_02_at_5_09_41_PM.png

以下是搜索栏处于活动状态时视图控制器的屏幕截图:
http://s4.postimg.org/tv71m8mrx/Screen_Shot_2015_09_02_at_5_10_04_PM.png

最佳答案 在storyboard或xib文件中,转到Attributes Inspector – >模拟的指标和更改状态栏从“推断”到“无”.

《UISearchBar没有在ios 8中的UIStatusBar下扩展其背景颜色》

点赞