I'm trying to change the Status Bar color in my Swift app to white, but am hitting a brick wall. I have 3 ViewControllers that are each embedded in a NavigationController (could that be the issue? I've already tried to place the code in the NavigationController class.) I've tried both of the following pieces of code in the didFinishLaunchingWithOptions of my AppDelegate.swift file but neither worked.
application.statusBarStyle = .LightContent
and
UIApplication.sharedApplication().statusBarStyle = .LightContent
All that the Docs have to say about it is that UIBarButtonStyle is an Int and gave me this enum snippet which didn't help me at all with implimentation.
enum UIStatusBarStyle : Int {
case Default
case LightContent
case BlackOpaque
}
What am I missing?
for me all above dind't work until i add:
so:
UIViewControllerBasedStatusBarAppearance
toYES
in.plist
viewDidLoad
callself.setNeedsStatusBarAppearanceUpdate();
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
navigationBar.barStyle
so finalfor light content:
override var preferredStatusBarStyle: UIStatusBarStyle { self.navigationController?.navigationBar.barStyle = .black;//or default return .lightContent //or default }
and for black content use default
The source from here and here.
and if this doesn't work you can try add a
UINavigationController
extension
:Strange, using Swift 3.1 & XC8.2.1, but all of the above didn't work.
What I did, is just
No Plist, no other stuff. HTH
You have to set the:
navigationController.navigationBar.barStyle = .black
and the text will appear in white
Step 1. Add to info.plist
View controller-based status bar appearance -> NO
Step 2. Add code in method where you need to change status bar color:
Key line of code:
setNeedsStatusBarAppearanceUpdate()
In Swift 3.0 you can override a getter in ViewController for View controller-based status bar appearance:
In Swift 3, status bar style has changed to a computed property in UIViewController that you can override like this: