Marcel Zanoni Marcel Zanoni - 1 month ago 8
iOS Question

Changing the default UIStatusBarStyle when using UIViewControllerBasedStatusBarAppearance

I'm developing an application containing several view controllers.
A few of those view controllers should use the

UIStatusBarStyleDefault
style, the rest should default to the
UIStatusBarStyleLight
style.

I want to use
preferredStatusBarStyle:
with
View controller-based status bar appearance
set to YES in my Info.plist. It would be nice if I don't need to implement
preferredStatusBarStyle:
in every single ViewController (there are a lot), but only in the ones using the default style. So I'm looking for the least possible code change in all of the VCs.

I've tried setting the "general" UIStatusBarStyle in the Target settings, but this doesn't change anything when View controller-based status bar appearance is set to YES.

Please don't provide answers using
UIApplication's
setStatusBarStyle:animated:
or the
statusBarStyle
property as these are deprecated and the reason why I'm asking this question.

Answer

The Default style is the default! So you do indeed add code only where you want the Light style.

Here's the thing to keep in mind. The API is that every top-level view controller dictates how it wants the status bar to appear. You probably don't have many of those. So not much code will be needed at all.