I have a UITabBarController as the root view controller. Each tab has a view controller embedded inside of a navigation controller. My navigation bars are a dark color so I need the status bar to be set to .lightContent. I also need to hide the status bar dynamically.
If I set "View controller-based status bar appearance" to "NO", I can set the status bar correctly to ".lightContent", but I cannot hide the status bar dynamically.
If I set "View controller-based status bar appearance" to "YES", the status bar will only set to ".lightContent" if a navigation bar is NOT present.
This is what I use in each view controller to show or hide the status bar:
var shouldHideStatusBar: Bool = false {
didSet { self.setNeedsStatusBarAppearanceUpdate() }
}
override var prefersStatusBarHidden: Bool { return shouldHideStatusBar }
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation { return .slide }
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
I have also tried:
navigationController?.navigationBar.barStyle = .black
There must be something I am missing in order to set the status bar to .lightContent and still be able to dynamically show and hide the status bar.