Photo by Igor Son on Unsplash

iOS Notes 13: How to change Status Bar Color on iOS 13 and Below? [UPDATED v2]

Kuray Ogun
FreakyCoder Software Blog

--

You can change the status bar colour just with a single line of code.

Updated at Oct 1, 2019

Just updated the markdown for iOS 13 and below. Also, tested!

iOS 13 and below you can change the status bar color

Github:

Gist:

Markdown:

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: "statusBarWindow.statusBar") as? UIView
statusBar?.backgroundColor = UIColor.red
}

That’s it :) Do not forget to use it on viewDidLoad function.

If you are using TabBarController this code segment should be on viewWillAppear function. This is important!

If you do not know how to change status bar style like this, you should check this out :) How to change status bar style?

If you have any question, ask me :)

--

--