Search code examples
iosswiftxcode-storyboarduistatusbar

Cannot set iOS Status Bar Colour for View


I am developing an app for iOS8, using Swift 1.2.

However, I am having an issue with the colour of the status bar (the one with the time, battery indicator etc).

In my Info.plist file, I have UIViewControllerBasedStatusBarAppearance set to YES as well as Status bar style set to UIStatusBarStyleLightContent and then in all my view controllers in the Storyboard, I have the status bar set to "Light Content".

enter image description here

This works for all of my NavigationViewControllers and views embedded within NavigationViewControllers, however I have one normal TableViewController which is not embedded in a NavigationController, and when I push this view modally, the status bar changes to BLACK!???

Even when I look at the view in the Storyboard editor it shows as a white status bar (note the faint white battery indicator at the right of the below screenshot):

enter image description here

But when I build and run on my iPhone, the status bar shows as black...

Why is this? How can I fix this? I don't know what could be incorrect.


Solution

  • UPDATE:

    I found the solution to this was very easy, from another StackOverflow article (Swift UIApplication.setStatusBarStyle Doesn't work).

    For anyone else wanting to set the status bar colour programmatically, I just inserted the following code into my ViewController for the view in question:

    - Swift 4.0+

    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent        
    }
    

    - Earlier Swifts (4.0-)

    override func preferredStatusBarStyle() -> UIStatusBarStyle {
        return .LightContent        
    }