Search code examples
iosswiftuitabbarcontrolleruistatusbar

How do I change the UIStatusBar color to .lightContent in the MoreTabBarController


I have a UITabBarController with more than 5 UIViewControllers. I have set the value in my info.plist I have set the value for ViewController based status bar appearance to YES.

enter image description here

All of the UIViewControllers have the values

UIApplication.shared.statusBarUIView?.backgroundColor = customColor
self.setNeedsStatusBarAppearanceUpdate()

in viewDidLoad with customColor being a dark shade of blue. I'm also overriding the preferredStatusBarStyle variable to light content.

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}

All UIViewControllers display the lightContent status bar. I have tried the same in the MoreTabBarController class but it doesn't work. I'm assuming the reason is because it isn't a UIViewController but rather a UITabBarController.

enter image description here

How do I change the Status bar color to light content in the MoreTabBarController?


Solution

  • Use UIApplication.shared.statusBarStyle = .lightContent in didFinishLaunchingWithOptions and then use View controller-based status bar appearance key and set No for its boolean value in .info plist. Its change Status bar color to light content.