1

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.

Max
  • 1,974
  • 2
  • 16
  • 24
  • Add one more key `Status bar style` -> `UIStatusBarStyleLightContent` – Kampai Jul 14 '15 at 13:03
  • Yep already have that (sorry, didn't mention in the question, but already have that too) – Max Jul 14 '15 at 13:06
  • Managed to find the solution on another post: http://stackoverflow.com/questions/24622960/swift-uiapplication-setstatusbarstyle-doesnt-work – Max Jul 14 '15 at 13:11

5 Answers5

3

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

freytag
  • 4,769
  • 2
  • 27
  • 32
  • I have it set to YES...why should I set it to NO? When I previously had it as NO, I had a different issue where the status bar would be white, but then when I would display a UIImagePicker and then dismissed the picker, the status bar would from then on always be black throughout the app (which is not correct...needs to be white) – Max Jul 14 '15 at 13:09
  • 2
    When you have YES, every controller can use its own style. When you set it to NO, the setting from the plist is always used. – freytag Jul 14 '15 at 13:40
3

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        
}
Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278
Max
  • 1,974
  • 2
  • 16
  • 24
2

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

Kampai
  • 22,848
  • 21
  • 95
  • 95
1

For Swift 3

in your AppDelegate.swift file in function didFinishLaunchingWithOptions

UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
Bartando
  • 719
  • 8
  • 26
0

add this Line in your Appdelegate.swift file :

UIApplication.sharedApplication().statusBarStyle = .LightContent
Jay Bhalani
  • 4,142
  • 8
  • 37
  • 50