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 could try to override the value returned, rather than setting it. The method is declared as { get }, so just provide a getter:
If you set this conditionally, you'll need to call
setNeedsStatusBarAppearanceUpdate()
so it'll animate the change when you're readyThis worked for me :) I have Navigation Controller embedded in my view controllers with navigation bar hidden. I wanted to set status bar light on some of the viewsin app.
iOS 11.2
I was getting:
Which is fixed by adding
public
like:On Swift3 iOS10.
Swift 4+
for white statusbar text:
To add to the great asnwer by @Krunal https://stackoverflow.com/a/49552326/4697535
In case you are using a
UINavigationController
, thepreferredStatusBarStyle
will have no effect on theUIViewController
.Xcode 10 and Swift 4.
Set a custom
UINavigationController
Example:
Use an extension for an app level solution: