8

I'm running into an issue with status bars & navigation bars. By default the navigation bar of UINavigationController extends behind the status bar and colors it (left screenshot).

When the search bar is used, I hide the navigation bar. This results in an uncolored Status Bar. Apple's Mail app does not have this issue.

Is there any other solution than creating a separate UIView with a background color and placing it behind the status bar?

Image that shows hidden and not-hidden navigation bar, and how this affects the status bar color

Here's what I'd like to accomplish:

enter image description here

Ben-G
  • 4,996
  • 27
  • 33

2 Answers2

0

When you hide the navigationBar why don't you also update the appearance of your UIStatusBar.

Implement this function in your NavigationController:

-(UIStatusBarStyle)preferredStatusBarStyle{
    //Have an if statement to determine which UIStatusBarStyle to return, i.e if the navigationBar is hidden 
    return UIStatusBarStyleLightContent; 
 }

And call it when you hide your navigation bar by using this:

 [self setNeedsStatusBarAppearanceUpdate];

Another option is to do the follow:

Set UIViewControllerBasedStatusBarAppearance to NO in your info pList file. Then you can call

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
chrissukhram
  • 2,957
  • 1
  • 13
  • 13
0

In your IB (or programatically), try to check the simulated metrics for the top bar: you should set it from opaque to translucent (navigation bar).

Note: By default, the navigation bar is translucent. You should get the "colored"** status bar for free.

** as defined by UISearchBar.appearance().barTintColor

StanislavK
  • 1,962
  • 15
  • 16