title: How do I programatically set the status bar background color for all view controllers in AppDelegate?
body: <p>Is there a way to programmatically set the status bar background color in the AppDelegate file so that this background color can be applied to all view controllers in a given app?</p>
  <p>I found the solution below from another Stack Overflow thread, but the problem is that this code needs to be applied to each and every view controller in the app, which I don't think is a sustainable solution. Thanks.</p>
  <pre><code>   if #available(iOS 13.0, *) {
     let app = UIApplication.shared
     let statusBarHeight: CGFloat = app.statusBarFrame.size.height
  
     let statusbarView = UIView()
     statusbarView.backgroundColor = UIColor.red
     view.addSubview(statusbarView)
  
     statusbarView.translatesAutoresizingMaskIntoConstraints = false
     statusbarView.heightAnchor
       .constraint(equalToConstant: statusBarHeight).isActive = true
     statusbarView.widthAnchor
       .constraint(equalTo: view.widthAnchor, multiplier: 1.0).isActive = true
     statusbarView.topAnchor
       .constraint(equalTo: view.topAnchor).isActive = true
     statusbarView.centerXAnchor
       .constraint(equalTo: view.centerXAnchor).isActive = true
  
     } else {
        let statusBar = UIApplication.shared.value(forKeyPath: 
     &quot;statusBarWindow.statusBar&quot;) as? UIView
        statusBar?.backgroundColor = UIColor.red
     }
  </code></pre>