I'm using Xcode 8.0 beta 4.
In previous version, UIViewController have method to set the status bar style
public func preferredStatusBarStyle() -> UIStatusBarStyle
However, I found it changed to a "Get ONLY varaiable" in Swift 3.
public var preferredStatusBarStyle: UIStatusBarStyle { get }
How can provide the style to use in my UIViewController?
You can also do this in storyboard
You will have to do this for each navigation controller you have. However, any views under that navigation controller will change all the view's status bars style/color to the one you just selected. I find this option better because you can see your results instantly and do not have to add extra lines of code in every view controller.
(Done with Xcode 8.3.3 in an all Swift project)
This worked for me
Set
View controller-based status bar
appearance into NO in plist then InUIViewController
viewDidAppear
just added the following lineYou can using a bool property named "shouldStatusBarDark" to toggle you status bar color. And you also could update its value to change the status bar color when you scrolling.
You need to add below key in your Info.plist file:
View controller-based status bar appearance
with boolean value set toNO
In your appdelegate class, in
didFinishLaunchingWithOptions
method before return.change
backgroundColor
andstatusBarStyle
as per requirement.Swift 4.0 Please use this code in "didFinishLaunchingWithOptions launchOptions:" Appdelegate class
Please Add the following line into your info.plist then only you can achieve it
"View controller-based status bar appearance = NO"
And add the following snippet into your code and see the output