Search code examples
swiftuinavigationcontrolleruitabbarcontroller

Using TabbarViewController the preferredStatusBarStyle not called


I have a TabbarViewController with different views, the problem is:

 override var preferredStatusBarStyle: UIStatusBarStyle {
          return .lightContent
      }

not called in any the of the views.

I have tried to add:

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

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

Nothing change, should I call this extension method in some where else?


Solution

  • I had to create a class of UInavigation Controller then add this methods to the class and it start to work.

     override open var childViewControllerForStatusBarStyle: UIViewController? {
            return self.topViewController
        
    }
       
        override open var preferredStatusBarStyle : UIStatusBarStyle {
            return topViewController?.preferredStatusBarStyle ?? .default
        
    }