After iOS 13 and Swift 5, we needI have a custom solution for changing status bar on iOS 13 and below. Here is how to do that:
if #available(iOS 13.0, *) {
let app = UIApplication.shared
let statusBarHeight: CGFloat = app.statusBarFrame.size.height
let statusbarView = UIView(frame:)
CGRect statusbarView.backgroundColor = UIColor.red
view.addSubview(x:statusbarView)
0, y: 0,statusbarView.translatesAutoresizingMaskIntoConstraints width= false
statusbarView.heightAnchor
.constraint(equalToConstant: UIScreenstatusBarHeight).mainisActive = true
statusbarView.boundswidthAnchor
.sizeconstraint(equalTo: view.widthwidthAnchor, heightmultiplier: statusBarHeight)1.0)
.isActive = true
statusbarView.backgroundColortopAnchor
.constraint(equalTo: view.topAnchor).isActive = UIColortrue
statusbarView.redcenterXAnchor
view .addSubviewconstraint(statusbarViewequalTo: view.centerXAnchor).isActive = true
} else {
let statusBar = UIApplication.shared.value(forKeyPath:
"statusBarWindow.statusBar") as? UIView
statusBar?.backgroundColor = UIColor.red
}
Gist
Also, check the article iOS 13 How to Change StatusBar Color? or Github Example: iOS StatusBar Example
One last thing, you can still change statusbar style with :
override var preferredStatusBarStyle : UIStatusBarStyle {
return UIStatusBarStyle.lightContent
//return UIStatusBarStyle.default // Make dark again
}