You need to find a way to store a variable that is of type UIStatusBarStyle
somewhere in your view controller.
Then in your view controller you add:
var preferredStatusBarStyle: UIStatusBarStyle {
return statusBarStyleVariable // This is the variable you created
}
When you want to switch the styles, just change the value of your statusBarStyleVariable
and do setNeedsStatusBarAppearanceUpdate()
EDIT:
This can be your variable code:
var statusBarStyleVariable: UIStatusBarStyle {
didSet {
setNeedsStatusBarAppearanceUpdate()
}
}
This way, whenever you change the value of the your variable, it'll refresh automatically.