5

Here's my implementation in a subclass of UIViewController:

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)
}

I tried putting it in AppDelegate initialisation code (using the passed in UIApplication instance), however the status bar is still black..

Is this a bug with iOS 8 or am I doing it wrong?

Note: I may be breaking someone's law's here by discussing ios 8.. Its a general problem that, when compiled doesn't work for ios 7 either.

Update: Still doesn't work, even with value in Info.plist and code in - didFinishLaunchingWithOptions Nope still doesn't work

Shruti Thombre
  • 989
  • 4
  • 11
  • 27
Matej
  • 9,548
  • 8
  • 49
  • 66
  • 2
    In the settings (`info.plist`) add `View Controller-Based Status Bar Appearance` and set it to `false` – Jack Jul 08 '14 at 02:54
  • @JackWu Added to `Info.plist` but no go – Matej Jul 08 '14 at 02:57
  • After you set that try calling `UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)` in the app delegate's `applicationDidLoad`. It should work... – Jack Jul 08 '14 at 03:02
  • @JackWu Hmmmmm, still doesn't work :/ – Matej Jul 08 '14 at 03:22
  • Which good soul downvoted? – Matej Jul 08 '14 at 03:24
  • Try the normal stuff... Clean.. Restart Xcode...also make sure it's the right info.plist...not a different target. – Jack Jul 08 '14 at 03:43
  • possible duplicate of [How to I hide the status bar in a Swift iOS app?](http://stackoverflow.com/questions/24236912/how-to-i-hide-the-status-bar-in-a-swift-ios-app) – drewag Jul 08 '14 at 04:26
  • 2
    @drewag I don't want to hide the status bar, but change its colour from `dark -> light` – Matej Jul 08 '14 at 08:07

2 Answers2

10

You really should implement preferredStatusBarStyle on your view controller(s):

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return .LightContent
}
drewag
  • 93,393
  • 28
  • 139
  • 128
9
  1. Go to Info.plist file
  2. Hover on one of those lines and a (+) and (-) button will show up.
  3. Click the plus button to add new key Type in start with capital V and automatically the first choice will be View controller-based status bar appearance.
  4. Add that as the KEY.
  5. Set the VALUE to "NO"
  6. Go to you AppDelegate.swift
  7. Add the following code, inside the method
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
    application.setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)

    return true
}
  1. DONE! Run your app and your status bar is now WHITE!
Sumner Evans
  • 8,951
  • 5
  • 30
  • 47
nycdanie
  • 2,921
  • 3
  • 18
  • 21
  • Nice. I figured it out using the comments though. Both answers are correct (currently accepted answer + this answer) – Matej Jan 28 '15 at 16:35
  • 1
    UIApplication's "setStatusBarStyle" method is deprecated as of iOS 9. Overriding "preferredStatusBarStyle" seems to be the preferred way to change the status bar text color. – Jim Rhoades Dec 07 '15 at 18:35