Max
Max

Reputation: 2094

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.

Upvotes: 1

Views: 5994

Answers (5)

Max
Max

Reputation: 2094

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        
}

Upvotes: 3

Bartando
Bartando

Reputation: 748

For Swift 3

in your AppDelegate.swift file in function didFinishLaunchingWithOptions

UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent

Upvotes: 1

Jay Bhalani
Jay Bhalani

Reputation: 4171

add this Line in your Appdelegate.swift file :

UIApplication.sharedApplication().statusBarStyle = .LightContent

Upvotes: 0

Mehul Patel
Mehul Patel

Reputation: 23053

These are setups for UIStatusBar style:

  1. Go to AppDelegate.swift in that add below code line in didFinishLaunchingWithOptions method:

    UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
    
  2. Add below keys into .plist file.

enter image description here

  1. In Storyboard select your controller UINavigationController or UIViewController. And set status bar style as Light Content

enter image description here

Upvotes: 2

freytag
freytag

Reputation: 4819

Please make sure to add View controller-based status bar appearance (UIViewControllerBasedStatusBarAppearance) with value NO to your Info.plist

Upvotes: 3

Related Questions