3

I'm looking for a way to change the backgroundcolor of the statusBar. There are similar questions, but they all requires a navigationBar. I found this answer, but it makes no sense. He uses properties who are deprecated.

For iOS 12 and below it was really simple to change the backgroundcolor:

let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
statusBar.backgroundColor = UIColor.black

But for iOS 13 it looks really complicated. Is there no similar way to change it?

jamesxbrown
  • 135
  • 2
  • 11
  • 1
    FYI - that iOS 12 code has never been valid or supported since it required digging into a private API. All such solutions, even if they work at one point, are prone to failure with any iOS update. – rmaddy Sep 14 '19 at 16:34
  • So, there is **no** official way to change the statusbar backgroundColor? – jamesxbrown Sep 14 '19 at 16:49

1 Answers1

0

You can use following way to change the status bar color. It will work for iOS 13. I hope it will work for you

guard let windowScene = (scene as? UIWindowScene) else { return }
if let statusBarFrame = windowScene.statusBarManager?.statusBarFrame {
     let statusBarHeight = statusBarFrame.size.height
     let statusBarView = UIView.init(frame: CGRect.init(x: 0, y: -statusBarHeight, width: UIScreen.main.bounds.width, height: statusBarHeight))
     statusBarView.backgroundColor = UIColor.yellow
     self.navigationController?.navigationBar.addSubview(statusBarView)
}

Here is reference link How to change the status bar background color and text color on iOS 7?

Mitesh
  • 504
  • 2
  • 8