rgamber
rgamber

Reputation: 5849

Status bar not the same color as the Navigation Bar

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

Upvotes: 5

Views: 1721

Answers (1)

Vini App
Vini App

Reputation: 7485

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.

Upvotes: 7

Related Questions