I know change status bar color with under the code.
override var preferredStatusBarStyle : UIStatusBarStyle {
return .default // or.lightContent
}
But for example, if I use this code with IBAction, how can write the right code?
I know change status bar color with under the code.
override var preferredStatusBarStyle : UIStatusBarStyle {
return .default // or.lightContent
}
But for example, if I use this code with IBAction, how can write the right code?
When you want your status bar's appearance to change, you can call setNeedsStatusBarAppearanceUpdate
on your view controller. In your @IBAction
example:
@IBAction func changeStatusBarStyle() -> Void{
// Do whatever you need to determine and set the next status bar style
setNeedsStatusBarAppearanceUpdate()
}
Note that if you call setNeedsStatusBarAppearanceUpdate
within an animation block, the style change will be animated
Set that the status bar needs to be updated when you click on the button. In this way 'preferredStatusBarStyle' will be called.
setNeedsStatusBarAppearanceUpdate()