How to Change the status bar color using ios with swift on internet reachability?
Tested in Swift & iOS9
If you use Navigation Controllers, put this in your viewcontroller class:
override func viewDidLoad(){
...
self.navigationController?.navigationBar.barStyle = .Black
}
Otherwise, override the preferredStatusBarStyle()
in your UIViewController:
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
You could find more information here
In your Info.plist
you need to set "View controller-based status bar appearance" to a boolean value.
If you set it to YES
then you should override preferredStatusBarStyle
function in each view controller.
If you set it to NO
then you can set the style in AppDelegate
using:
UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
override func viewWillAppear(animated: Bool) {
self.navigationController?.navigationBarHidden = true
//Status bar style and visibility
UIApplication.sharedApplication().statusBarHidden = false
UIApplication.sharedApplication().statusBarStyle = .LightContent
//Change status bar color
let statusBar: UIView = UIApplication.sharedApplication().valueForKey("statusBar") as! UIView
if statusBar.respondsToSelector("setBackgroundColor:") {
statusBar.backgroundColor = UIColor.redColor()
}
}