Isa Ranjha Isa Ranjha - 1 year ago 210
iOS Question

UISearchController changing status bar color on invocation

I have the following code in my app, specifically in

that sets up my

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
) is invoked, the
color changes from
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
color is preserved. However, another issue arises. When
is set to

, upon invocation the search bar shifts down for some reason, coincidently (or rightfully so) right under where the bottom of the
displays on the

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download