Since UIApplication.shared.setStatusBarStyle(.default, animated: true)
is deprecated from IOS9 is it possible to change status bar style with animation on push
? I cannot find any description in docs.
It's now a variable you have to override:
override var preferredStatusBarStyle: UIStatusBarStyle
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation
Depending on when you update the status bar, you might also have to call setNeedsStatusBarAppearanceUpdate()
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.
To tackle the animation part the way I made it transition smoothly between .lightContent
and .default
was to use something similar to below each time you change it.
UIView.animate(withDuration: 0.2) {
self.setNeedsStatusBarAppearanceUpdate()
}
Place that in your VC you want the status bar to animate and you'll have a nice smooth animation.
override var preferredStatusBarStyle: UIStatusBarStyle {
return lightStatusBar ? .lightContent : .default
}
Above is a snippet of me changing the content based on a condition I have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With