I want to change the color of status bar (battery percentage, time and wifi, etc) to a custom color (red, yellow, blue, etc) other than .lightContent
and .darkContent
that Apple offers. Is that even possible to do so? if yes please help me to solve this problem. I have seen the answers on google and stackoverflow, but they only change the backgroundColor mostly the deprecation of keyWindow. I am using Swift 5 and iOS 14.4
.
Asked
Active
Viewed 1,255 times
2

Ulugbek
- 127
- 3
- 15
1 Answers
1
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!

Piyush Sharma
- 99
- 10
-
thank you for you response and answer, but i dont want to change the backgroundColor, i want to change the font color of the items that are in status bar – Ulugbek Mar 25 '21 at 09:34
-
is that even possible? – Ulugbek Mar 25 '21 at 09:34