5

I have a Navigation Controller, where I am coloring my navigation bar with some color, and I want the status bar (which shows the carrier, wifi symbol, etc) to use the same color.

So in Info.plist, I have set View controller-based status bar appearance equal to NO. And in the Target > Deployment Info I set the Status Bar Style > Light:

enter image description here

I can see that the status bar is now indeed using the "light" style as the text is light/white. But the status bar background is still not the same as the Navigation bar as seen below. How can I correct this?

enter image description here

rgamber
  • 5,749
  • 10
  • 55
  • 99

1 Answers1

7

You have to use like this :

if let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as? UIView {
    statusBar.backgroundColor = UIColor.purple
}

If you want to change the status bar color all over the app, use it in appdelegate->didFinishLaunchingWithOptions. Or if you want to change for any particular screen, then call it in the particular viewDidLoad.

Vini App
  • 7,339
  • 2
  • 26
  • 43
  • 1
    It works, but I am not sure if this is the optimal solution. When I change the status bar style to "light", it should automatically assume the color of the Navigation Bar, right? – rgamber Oct 24 '17 at 04:45
  • @rgamber, did you find a more optimal solution? – sbru Jan 09 '18 at 18:49
  • 1
    Unfortunately no. Nothing else seems to work, so temporarily resorted to this. If you find any other way, please post it here! – rgamber Jan 09 '18 at 18:51