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:
override func viewWillAppear(_ animated: Bool) {
let nav = self.navigationController?.navigationBar
nav?.barTintColor = .red
nav?.tintColor = .white
nav?.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
setNeedsStatusBarAppearanceUpdate()
}
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 :)