UISearchController changing status bar color on invocation

user2284295 picture user2284295 · Aug 6, 2015 · Viewed 7.5k times · Source

I have the following code in my app, specifically in viewDidLoad: that sets up my UISearchController.

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.definesPresentationContext = NO;
self.searchController.searchBar.scopeButtonTitles = @[];
self.searchController.searchBar.searchBarStyle = UISearchBarStyleProminent;

[_tableView setTableHeaderView:_searchController.searchBar];

Whenever the search bar (which is added to the tableView) is invoked, the UIStatusBar color changes from UIStatusBarStyleLightContent to dark (white to black). Now, I figured out if I set,

self.definesPresentationContext = NO;

to the following:

self.definesPresentationContext = YES;

the issue is solved and the UIStatusBar color is preserved. However, another issue arises. When self.definesPresentationContext is set to YES , upon invocation the search bar shifts down for some reason, coincidently (or rightfully so) right under where the bottom of the UIRefreshControl displays on the tableView.

Answer

pfandrade picture pfandrade · Aug 11, 2015

Setting View-controller based status bar appearance to No is not a solution if you want the view controllers to define how the status bar looks.

My solution consisted of two things:

  1. Make sure the presenting view controller has definesPresentationContext set to YES
  2. Make sure both the view controller that is pushed and the pushing view controller are laid out beneath the navigation bar (set extendedLayoutIncludesOpaqueBars to YES)