Zack Shapiro Zack Shapiro -4 years ago 134
Swift Question

Changing status bar style mid-scroll


was deprecated in iOS 10, is there a way to change my status bar from white to black or vice versa while doing something like scrolling through a scroll view?

I see the
property on
but I'd like something more granular that I can control while a user uses the view controller itself.

Answer Source

if you override preferredStatusBarStyle and then call setNeedsStatusBarAppearanceUpdate() when you need, that should work the same way.

class MyViewController: UIViewController {

	var currentStyle = UIStatusBarStyle.default

	override var preferredStatusBarStyle: UIStatusBarStyle {
        return currentStyle
    // ...

	// here are the actions that change the status bar
	func myFunction(){
		// ...
		// condition that would determine the preferred style
		currentStyle = .lightContent


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download