title: iOS: Specify status bar text color when using UINavigationBarAppearance now barstyle is ignored
body: <h1>Problem</h1>
  <p>I have an app that has different colour navigation bars for different flows. Some navigation bars have a light background and require black status bar text. Others have a darker navigation bar and require white status bar text.</p>
  <p>As part of the move to iOS15 I have updated an app I am working on to use the <code>UINavigationBarAppearance</code> approach to navigation bar styling.
  I am able to style everything as I could before other than the status bar color.
  <br /><br /></p>
  <p>Previously I have been using the <code>barStyle</code> property on navigation bar to set the status bar text color.</p>
  <pre><code>navigationBar.barStyle = .black
  </code></pre>
  <p>This does not appear to work when using  <code>UINavigationBarAppearance</code>.</p>
  <h1>Sample code</h1>
  <p><strong>Old styling approach</strong></p>
  <pre><code>    override func viewDidLoad() {
          super.viewDidLoad()
          
          let navigationBar = navigationController?.navigationBar
          
          // Style using old approach
          navigationBar?.barTintColor = UIColor.purple
          navigationBar?.titleTextAttributes = [.foregroundColor: UIColor.white]
          
          // Use barStyle to set status bar text color to white
          // This only work when using the old styling approach
          navigationBar?.barStyle = .black
      }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/pMYi9.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/pMYi9.jpg" alt="enter image description here" /></a></p>
  <p><strong>New styling approach</strong></p>
  <pre><code>    override func viewDidLoad() {
          super.viewDidLoad()
          
          let navigationBar = navigationController?.navigationBar
          
          // Style nav bar using new Appearance API
          let navBarAppearance = UINavigationBarAppearance()
          navBarAppearance.backgroundColor = UIColor.purple
          navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
  
          navigationBar?.standardAppearance = navBarAppearance
          navigationBar?.scrollEdgeAppearance = navBarAppearance
          
          // Use barStyle to set status bar text color to white
          // This only work when using the old styling approach
          navigationBar?.barStyle = .black
      }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/NkaSe.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/NkaSe.jpg" alt="enter image description here" /></a></p>
  <h1>Alternatives</h1>
  <p><strong>Force dark/light mode on the navigation bar</strong></p>
  <p>It is possible to make the status bar text white using the property <code>overrideUserInterfaceStyle</code>. To make the status bar text white, set</p>
  <pre><code>navigationBar.overrideUserInterfaceStyle = dark
  </code></pre>
  <p>However, this results in menus from buttons in the nav bar in dark mode too which is not what I want.</p>
  <p><a href="https://i.stack.imgur.com/fcCjM.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/fcCjM.jpg" alt="enter image description here" /></a></p>
  <p><strong>Subclass UINavigationController</strong></p>
  <p>I imagine I could also subclass UINavigationController and explicitly override the <code>preferredStatusBarStyle</code> to force black or white text.</p>
  <p>Having to use a subclass everywhere we make new navigation controllers just to specify the status bar text color seems a bit extreme.</p>
  <p><strong>Anything else?</strong></p>
  <p>I'm not sure if there is a better approach to this?</p>