1

I've tried adding key UIViewControllerBasedStatusBarAppearance to true inside info.plist file and then added the below code inside UINavigationController class which holds several UIViewController classes.

class HomeNavigationController: UINavigationController {

    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }
}

But, it did not work.

I've also tried setting the barStyle property of navigationBar to .black but that too didn't work either.

Also looked up to https://stackoverflow.com/a/58203998/9180494, but that did not help as well.

Please NOTE: For UIViewController classes not embedded inside any UINavigationController , if I use computed property preferredStatusBarStyle, then it works.

Anuranjan Bose
  • 201
  • 1
  • 3
  • 16

2 Answers2

3

Try in viewDidAppear() of UINavigationController class:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    navigationController?.navigationBar.barStyle = .black
}

Also add (in the same class as above):

override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}
Anuranjan Bose
  • 201
  • 1
  • 3
  • 16
Tom
  • 513
  • 2
  • 5
  • 20
1

@Anuranjan Bose Try this on your view did load,

override func viewDidLoad() {
    super.viewDidLoad()
    setNeedsStatusBarAppearanceUpdate()
}
Ram
  • 764
  • 1
  • 7
  • 20