I would like to change the status bar color between .lightContent
and .default
dynamically (since my background can change in the same ViewController).
I hope below code will use for your need (for Swift4):
override func viewDidLoad() {
super.viewDidLoad()
let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView
if statusBar?.responds(to: #selector(setter: UIView.backgroundColor)) ?? false {
statusBar?.backgroundColor = .green
}
}
Alternatively, you could try this:
if let StatusbarView = UIApplication.shared.value(forKey: "statusBar") as? UIView {
StatusbarView.backgroundColor = .green
}