Swift ViewController ignores status bar style

I’m writing a Swift iOS App with multiple views. I’ve set the App to allow ViewController based status bar settings which allows me to set the status bar style to have light content using the following code

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent

That worked like expected. But then I’ve embedded the views in an NavigationController and connected a BarButtonItem with a showSegue. Since then the ViewController of the view switched to ignores the style settings and shows a black status bar. I tried everything to change its appearance but had no luck.

  • How to make UIImagePickerController StatusBar lightContent style?
  • How to change UIStatusBarStyle in iOS 7 in modal views with navigation bar?
  • setStatusBarHidden(_:withAnimation:) deprecated in iOS 9
  • Programmatically build / navigate a Navigation Controller
  • how to fix status bar overlap issue in ios 7
  • A home button in iOS 5, xcode 4.2, Story board
  • Any ideas?

    Solutions Collect From Internet About “Swift ViewController ignores status bar style”

    When you’re in a navigation controller that will not get called. The navigation controller’s preferredStatusBarStyle will be called. Try this along with your code:

    extension UINavigationController {
       open override var preferredStatusBarStyle: UIStatusBarStyle {
          return topViewController?.preferredStatusBarStyle ?? .default