I'm trying to change the status bar text to white on some of the view controllers, but on a few others it still needs to be black. (so cannot change it globally for the whole app).
Everything works fine, except the first few seconds, when clicking on different tab bars, when there is a glitch, and half of the status bar text becomes black, instead of white. Then everything updates perfectly.
The structure is like this: A tab bar controller with a few tabs, each tab containing a navigation controller, containing a view controller.
Having navigation controllers made it necessary to change the navigationController?.navigationBar.barStyle = .black
to make it work.
After pressing a few times on tabs, it works fine.
First thing I did of course was to set to YES
the View controller-based status bar appearance
from the .plist
I also have override the preferredStatusBarStyle, using a boolean to set which view controllers should have the white or black status bar text:
override var preferredStatusBarStyle: UIStatusBarStyle {
return coloredNavigationBar ? .lightContent : .default
}
var coloredNavigationBar: Bool = true
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if coloredNavigationBar {
navigationController?.navigationBar.barStyle = .black
} else {
navigationController?.navigationBar.barStyle = .default
}
setNeedsStatusBarAppearanceUpdate()
}
The code pasted is from the base view controller used everywhere.
preferredStatusBarStyle
is not called. A navigation controller gets the status bar style from the navigation bar style. But also, you've got a tab bar controller as your top level view controller, so it gets to say what the status bar style is. You should probably be giving the tab bar controller a delegate so it can set the status bar style as needed. – matt