0

I'm trying to set up dark mode for my app but noticed that my status bar is the opposite color that it should be. When in light mode it's dark and when in dark mode it's light.

Here it is in light mode (showing wrong dark colors for status bar) Here it is in light mode (showing wrong dark colors for status bar)

Here it is in dark mode (showing wrong light colors for status bar)

enter image description here

Ideally I would like to reverse these status bar colors so when its in light mode the status bar is light (white) and when in dark mode the status bar is dark (black).

Any help would be highly appreciated, and thank you ahead of time!

Robert Harrison
  • 107
  • 1
  • 10

1 Answers1

1

You can set the status bar style manually if you want to have custom control over the status bar. Override preferredStatusBarStyle in your view controller

class MyViewController: UIViewController {
    override var preferredStatusBarStyle: UIStatusBarStyle {
        switch traitCollection.userInterfaceStyle { // Light Mode vs. Dark Mode
        case .light:       return .lightContent
        case .dark:        return .darkContent
        case .unspecified: return .darkContent // <-- should never happen
        }
    }
}

See userInterfaceStyle, preferredStatusBarStyle, and preferredStatusBarStyle is not working for additional details.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117