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.
-
UIApplication.shared.statusBarStyle = .lightContent Have you used this – Lalit kumar Feb 24 '17 at 16:55
-
This will not change the bar with animation – Danny Feb 24 '17 at 17:18
3 Answers
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()

- 3,176
- 2
- 12
- 11
-
-
-
-
1
-
1The problem was that I previously set View controller-based status bar appearance to NO – Danny Feb 24 '17 at 18:34
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:
- Set the
UIViewControllerBasedStatusBarAppearance
toYES
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.

- 77,632
- 48
- 245
- 261
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.