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?
Swift 3 & 4, iOS 10 & 11, Xcode 9 & 10
For me, this method doesn't work:
when I used to each view controller, but this worked:
In file info.list, add row:
View controller-based status bar appearance
and set toNO
Next in appdelegate:
using WebkitView
Swift 9.3 iOS 11.3
Xcode 8.3.1, Swift 3.1
Create a new entry in info.plist "View controller-based status bar appearance" set it to "NO".
Open AppDelegate.swift and add these lines in "didFinishLaunchingWithOptions" method:
application.statusBarStyle = .lightContent
For people looking to change status bar for all viewcontrollers on: iOS 11, Swfit 4 solution is pretty easy.
1) Info.plist add:
2) Left side of XCode slect project > Targets > Select your project > Under General > Deployment Info > Select Status Bar Style: Light
If you want to change status bar only for one viewcontroller, on viewDidLoad add:
There seems to be a small issue about the status bar text colour when dealing with navigation bars.
If you want the .plist entry View controller-based status bar appearance set to
YES
, it sometimes won't work when you have a coloured nav bar.For example:
and
override var preferredStatusBarStyle: UIStatusBarStyle {return .lightContent}
The code above won't work even if you have set the following in the AppDelegate:
UIApplication.shared.statusBarStyle = .lightContent
For those still struggling, apparently it somehow judges if the status bar needs to be light or dark by the styles in the nav bar. So, I managed to fix this by adding the following line in viewWillAppear:
nav?.barStyle = UIBarStyle.black
When the bar style is black, then it listens to your overridden variable. Hope this helps someone :)
swift 3
if View controller-based status bar appearance = YES in Info.plist
then use this extension for all NavigationController
if there is no UINavigationController and only have UIViewController then use Below code: