Created
July 11, 2023 07:16
-
-
Save Innovatewithapple/b1474dae333cb713e855896d2aa27c8f to your computer and use it in GitHub Desktop.
iOS Status bar color change working with iOS13+. Call this function in viewDidLoad() method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func SetupStatusBar(color:String) { | |
if #available(iOS 13.0, *) { | |
let app = UIApplication.shared | |
let statusBarHeight: CGFloat = app.statusBarFrame.size.height | |
let statusbarView = UIView() | |
statusbarView.backgroundColor = UIColor(hexString: color) | |
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