18

I've try to modify status bar color text but no one answer from this thread doesn't work. Any especially for XCode 6?

I've tried insert:

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

to UIViewController

also

UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)

to AppDelegate.swift And I've tried change it in info.plist But it doesn't affect it. How change status bar color text to white?

Community
  • 1
  • 1
Max
  • 1,341
  • 3
  • 20
  • 39

5 Answers5

51

In your Info.plist you need to define View controller-based status bar appearance to any value.

enter image description here

If you define it YES then you should override preferredStatusBarStyle function in each view controller.

If you define it NO then you can set style in AppDelegate using

UIApplication.sharedApplication().statusBarStyle = .LightContent

Jordan
  • 424
  • 5
  • 19
Keenle
  • 12,010
  • 3
  • 37
  • 46
  • 1
    I got it! I've just don't have "View controller-based status bar appearance" in info.plist. I added it manually and define. Thanks. – Max Jul 15 '14 at 08:17
  • I'd try this in many ways however i can't manage to make it change the color of the UIStatusBar :( – Jorge Vicente Mendoza Jul 28 '14 at 21:14
  • @JorgeVicenteMendoza, does it always transparent? – Keenle Jul 28 '14 at 21:23
  • Always Dark! i did try adding the values in the info.plist, trying to override the function in the view controller calling the self.setNeedsStatusBarAppearanceUpdate() (that use to work in iOS7) but haven't been hable to make it light – Jorge Vicente Mendoza Jul 28 '14 at 21:24
  • Do you have UINavigationController or UITabBarController that presents your view controller were you try the override? – Keenle Jul 28 '14 at 21:39
  • 1
    Xcode 6, with Swift: 1. Info.plist, add this property: View controller-based status bar = NO 2. In AppDelegate.swift, inside applicationDidFinishLaunching, add this line: UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent – ObjectiveTC Dec 11 '14 at 23:47
  • Remember if you're in a UINavigationController you need a custom subclass where you'll override preferredStatusBarStyle. – Mannix Sep 01 '15 at 14:11
3

Just set " View controller-based status bar appearance == NO " in to your plist and put a single line in your appdelegate class in didfinshLaunching method.

 UIApplication.sharedApplication().statusBarStyle = .LightContent
Abhimanyu Daspan
  • 1,095
  • 16
  • 20
2

Swift 3.0

Just set View controller-based status bar appearance == NO in to your *.plist and put below code in your appdelegate class in didFinishLaunchingWithOptions method before return.

let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
if statusBar.responds(to:#selector(setter: UIView.backgroundColor)) {
    statusBar.backgroundColor = UIColor.red
}
UIApplication.shared.statusBarStyle = .lightContent

You can change backgroundColor and statusBarStyle as per your requirement.

Himanshu padia
  • 7,428
  • 1
  • 47
  • 45
1

Be sure to set the View controller-based status bar appearance in your info.plist file to Yes.

Furthermore, if you are in a UINavigationController, you cannot simply set the style in ViewControllers in it. Subclass the UINavigationController and add this to it:

override func preferredStatusBarStyle() -> UIStatusBarStyle {

    if let vc = self.viewControllers?.last as? UIViewController {
        return vc.preferredStatusBarStyle()
    }

    return super.preferredStatusBarStyle()
}

Now you can set the bar style in the UIViewController subclass and the UINavigationController will listen to it :).

Kevin R
  • 8,230
  • 4
  • 41
  • 46
0

Keenle is right on, from iOS7 onward, you have to opt out of viewController-based status bar styles before you can set it app-wide.

doc:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/occ/instm/UIApplication/setStatusBarStyle:animated:

"To opt out of the view controller-based status bar appearance behavior, you must add the UIViewControllerBasedStatusBarAppearance key with a value of NO to your app’s Info.plist file, but doing so is not recommended."

Sameer J
  • 226
  • 3
  • 13