Reputation: 154
I'm trying to implement a button that changes the background of my app from white to black along with the colour of the status bar. Right now I have
@IBAction func buttonTapped(_ sender: Any) {
self.view.backgroundColor = UIColor.black
UIApplication.shared.statusBarStyle = .lightContent
}
This doesn't seem to work. Does anyone know of a way of changing the colour of the status bar font without reloading the entire view?
Upvotes: 3
Views: 928
Reputation: 79756
If you want to set status bar style, application level then set UIViewControllerBasedStatusBarAppearance
to NO
in your .plist
file.
if you wan to set status bar style, at view controller level then follow these steps:
UIViewControllerBasedStatusBarAppearance
to YES
in the .plist
file, if you need to set status bar style at UIViewController level only. In the viewDidLoad add function - setNeedsStatusBarAppearanceUpdate
override preferredStatusBarStyle in your view controller.
-
override func viewDidLoad() {
super.viewDidLoad()
self.setNeedsStatusBarAppearanceUpdate()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
Set value of .plist according to status bar style setup level.
Upvotes: 2