How to Change Background Color of Status Bar?

I don't want transculent navigationbar in my app. So, I added this code to change it. It works but there is a little problem. If I use largeTitle navigation, status bar color is looks gray. How can I deal with it ? Thanks in advance.

UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().barTintColor = UIColor.white
UINavigationBar.appearance().backgroundColor = UIColor.white

Screenshot

Upvotes: 2

Views: 6263

Answers (2)

Asperi
Asperi

Reputation: 258441

Try this

   let navBarAppearance = UINavigationBarAppearance()
   navBarAppearance.configureWithOpaqueBackground()
   navBarAppearance.backgroundColor = UIColor.white

   UINavigationBar.appearance().standardAppearance = navBarAppearance

Upvotes: 1

Frankenstein
Frankenstein

Reputation: 16371

You could fix it by adding a subview on top of status-bar using UIStatusBarManager.

if #available(iOS 13, *) {
    let keyWindow = UIApplication.shared.connectedScenes
        .filter({$0.activationState == .foregroundActive})
        .map({$0 as? UIWindowScene})
        .compactMap({$0})
        .first?.windows
        .filter({$0.isKeyWindow}).first
    let statusBar = UIView(frame: (keyWindow?.windowScene?.statusBarManager?.statusBarFrame)!)
    statusBar.backgroundColor = .white
    keyWindow?.addSubview(statusBar)
}

Upvotes: 3

Related Questions