iOS correctly set the status bar style color

When developing iOS apps,Many applications need to set the color of the iOS system status bar according to the current App content color,Black or white-especially on iOS 13 After the system supports the black mode。

Normal,Others will tell you to do this:

But this triggers a warning: Deprecated in iOS 9 。So is there any other way? Have,The official recommendation is this:

This is only in your ViewController ... but you find it in despair,It is not called at all。

So you continue to search ...

At your Info.plist in, View controller-based status bar appearance Must be set to YES ,Otherwise, you can only set the black and white color of the status bar in the Xcode target。

but…… preferredStatusBarStyle Still not called。

What exactly is going on?

This is actually due UINavigationController Lead,Because it is usually the highest level in ViewController,It won't preferredStatusBarStyle Request to pass down,in contrast,It will be based on its own UINavigationBar.barStyle Properties to determine whether the system status bar is black or white,in case barStyle Yes .black ,Then the system bar is .lightContent Which is white;but if barStyle Yes .default ,Then the system bar is also the default black。

So,If you want to change the system bar color,in UINavigationController ViewController under the need to be modified UINavigationBar.barStyle Instead of rewriting preferredStatusBarStyle


If you are on iOS 13 Do this in iOS above,You will find that the system status bar remains the same ... so you may need to Info.plist Add UIUserInterfaceStyle Field,And set the value Light ,This can make your app unsuitable for iOS 13 Black mode-because if it fits,In black mode,Your system status bar will always be white,Does not change color ...


Original article written by Gerber drop-off:R0uter's Blog » iOS correctly set the status bar style color

Reproduced Please keep the source and description link:

About the Author


The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

Leave a Reply

Your email address will not be published. Required fields are marked *