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
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 :).
In your Info.plist you need to define View controller-based status bar appearance to any value.
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
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
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.
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."