preferredStatusBarStyle not respecting on iOS 13

I recently ran into this problem and these extensions seemed to fix the issue.

extension UITabBarController {
    open override var childForStatusBarStyle: UIViewController? {
        return selectedViewController?.childForStatusBarStyle ?? selectedViewController
    }
}

extension UINavigationController {
    open override var childForStatusBarStyle: UIViewController? {
        return topViewController?.childForStatusBarStyle ?? topViewController
    }
}

I just put them into a file called UIViewController+StatusBar.swift and included it in the project.


The correct answer referenced by @matt is navigationController?.navigationBar.barStyle = .lightContent in viewDidLoad.

Tags:

Ios

Swift