Search code examples
iosxcodeuinavigationcontrollerstatusbarswrevealviewcontroller

How to change background color of UIStatusBar when using a UINavigationController in Xcode?


In my project I've integrated the SWRevealViewController, and while I was setting it up I noticed that one of my view controllers - managed by a UINavigationController - had a black status bar even though the background color of the view controller is white. How can I change the Status Bar color back to white? (Either programmatically or in the Interface Builder)


Solution

  • If below the status bar is a navigation bar, the status bar style will be adjusted to match the navigation bar style (UINavigationBar.barStyle):

    Specifically, if the navigation bar style is UIBarStyleDefault, the status bar style will be UIStatusBarStyleDefault; if the navigation bar style is UIBarStyleBlack, the status bar style will be UIStatusBarStyleLightContent.

    So in your case as status bar is black, If you want UIStatusBarStyleLightContent on a UINavigationController use:

       self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    

    Also you can refer: preferredStatusBarStyle isn't called