UISearchController color change of status bar on call

I have the following code in my application, especially in viewDidLoad: which sets 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 a search string is called (which is added to the tableView ), the color of the UIStatusBar changes from UIStatusBarStyleLightContent to dark (white to black). Now, I realized if I installed,

 self.definesPresentationContext = NO; 

to the next:

 self.definesPresentationContext = YES; 

The problem is resolved and the color of the UIStatusBar maintained. However, another problem arises. If the self.definesPresentationContext parameter self.definesPresentationContext set to YES , when you call, the search string is shifted for any reason, by coincidence (or by right) right below where the UIRefreshControl displayed on the tableView at the tableView .

+6
source share
6 answers

Setting View-controller based status bar appearance to No not a solution if you want view controllers to determine what the status bar looks like.

My solution consisted of two things:

  • Verify that the definesPresentationContext set to YES
  • Make sure that both the view controller that was clicked and the pushing view controller are laid out under the navigation bar (set extendedLayoutIncludesOpaqueBars to YES )
+3
source

I needed full control over the color of the status bar. I use the extensions found here to make sure that the visible view controller sets the preferred color of the status bar.

For me, it was necessary to override the UISearchController and override the preferredStatusBarStyle and return the desired style.

+1
source

Like iOS 10 (maybe earlier?), If you have the โ€œView controller-based control panel statusโ€ set to YES in your Info.plist, just set your preferred StatusBarStyle to the UIViewController that includes the UISearchController.

 - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } 

(you don't need to subclass or create a UISearchController category / extension to override preferredStatusBarStyle ... it uses the preferredStatusBarStyle that you set in your UIViewController)

+1
source

If the ViewController is inside a TabBarController, then -

Instead self.definesPresentationContext = YES;

Use self.tabBarController.definesPresentationContext = YES;

This worked for me in the scenario described above.

+1
source

The status bar displayed when the search controller is displayed (active) belongs to the search controller. To set your preferred status bar style, you must add a category to the UISearchController and then override the preferredStatusBarStyle method.

The following is an example category implementation file:

 @implementation UISearchController (Customization) -(UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } @end 
0
source

Or we can write the extension in Swift (version 2, but you can easily translate it to 3):

 extension UISearchController { override public func preferredStatusBarStyle() -> UIStatusBarStyle{ if Theme.lightTheme() { return UIStatusBarStyle.Default } else { return UIStatusBarStyle.LightContent } } } 

Where Theme is the class that adjusts the theme color of the application.

0
source

All Articles