skip to Main Content

Before updating to xcode 13, the status bar’s background color matched the color of the navigation bar. When I updated to xcode 13, the status bar is behaving strangely. It is showing different background colors in different view controllers. Some are black, some are gray, and some are transparent. I tried overriding the status bar style but it didn’t work. There has been no change in the code whatsoever since the update. I want the status bar’s background color to match that of the navigation bar.

Status bar comparison before and after xcode 13

2

Answers


  1. You did not give code example how you are setting status bar – are you using statusBarManager? Maybe you are using some code that became deprecated?

    You can try set it with extension with statusBarManager in viewDidAppear:

    extension UINavigationController {
    
        func setStatusBar(backgroundColor: UIColor) {
            let statusBarFrame: CGRect
            if #available(iOS 13.0, *) {
                statusBarFrame = view.window?.windowScene?.statusBarManager?.statusBarFrame ?? CGRect.zero
            } else {
                statusBarFrame = UIApplication.shared.statusBarFrame
            }
            let statusBarView = UIView(frame: statusBarFrame)
            statusBarView.backgroundColor = backgroundColor
            view.addSubview(statusBarView)
        }
    }
    

    And then in your view call it like:

    self.navigationController?.setStatusBar(backgroundColor: #COLOR) 
    self.navigationController?.navigationBar.setNeedsLayout() 
    
    Login or Signup to reply.
  2. SwiftUI answer:

    Try adding .ignoresSafeArea() to whatever parent of your child views is. I encountered a similar issue back in the day and solved it by something like this:

    struct HomeView: View {
        var body: some View {
            VStack {
                <code>
                
                Spacer()
            }.ignoresSafeArea()
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search