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
}
Last active
June 15, 2022 08:52
-
-
Save WrathChaos/5c4498e4ebfc19ca1de8983a485d587e to your computer and use it in GitHub Desktop.
iOS 13 and Below How to change Status Bar Color?
It would be helpful if you make a function which adds or remove the background view in status bar based on a flag value.
I can update it if you wanna contribute it :) In general, people just need these other things like your advice would be so specific.
'statusBarFrame' was deprecated in iOS 13.0: Use the statusBarManager property of the window scene instead.
var statusBarTagNumber = 1
if #available(iOS 13.0, *) {
let app = UIApplication.shared
let statusBarHeight: CGFloat = app.statusBarFrame.size.height
for subview in view.subviews {
if subview.tag == statusBarTagNumber {
subview.backgroundColor = backgroundColor
return
}
}
let statusbarView = UIView()
statusbarView.tag = statusBarTagNumber
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
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be helpful if you make a function which adds or remove the background view in status bar based on a flag value.