I'm finding it hard to change the status bar style programatically.
I see how to statically set it for each ViewController using a combo of (in ViewController.swift):
override var preferredStatusBarStyle: UIStatusBarStyle {
return UIStatusBarStyle.default
}
and (in info.plist):
View controller-based status bar appearance = YES
...
I'm looking to change it whenever I want!
Found the answer after quite a lot of digging!
Set (in info.plist):
View controller-based status bar appearance = NO
and remove the (in ViewController.swift):
override var preferredStatusBarStyle: UIStatusBarStyle {
return UIStatusBarStyle.default
}
...
Now you can use (in ViewController.swift):
UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.lightContent, animated: true)
And, to initially set the style for each ViewController, use viewDidAppear:
override func viewDidAppear(_ animated: Bool) {
UIApplication.shared.setStatusBarStyle(UIStatusBarStyle.lightContent, animated: false)
}
swift 3
1.Change in info.plist the row View controller-based status bar appearance and set it to NO
2.Change in appDelegate.swift in didFinishLaunchingWithOptions
UIApplication.shared.statusBarStyle = .lightContent
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With