The status bar is not the same as the navigation bar

I have a navigation controller where I color my navigation bar with some color and I want the status bar (which shows the media, Wi-Fi symbol, etc.) to use the same color.

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

enter image description here

I see that the status bar now really uses a "light" style, as the text is light / white. But the status background is still not the same as the navigation bar, as shown below. How can i fix this?

enter image description here

+5
source share
1 answer

You need to use it like this:

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

If you want to change the color of the status bar throughout the application, use it in appdelegate->didFinishLaunchingWithOptions . Or, if you want to change a particular screen, call it in a specific viewDidLoad .

+6
source

Source: https://habr.com/ru/post/1272809/


All Articles