1

Good time of day everyone! iOS 7 welcomed us with many not-so-funny and not-so-documented 'features', especially in terms of appearance cusomization. My issue is the following:

I set 'View controller-based status bar appearance' to YES in my application plist, how do I now get current statusbar style programmatic? Old code like

[UIApplication sharedApplication].statusBarStyle 

always returns UIStatusBarStyleDefault disregard the style from viewcontroller.

To prevent future misunderstanding: I have NO intention to make statusBarStyle property working, I'm looking for new way with 'View controller-based status bar appearance' turned on. PLEASE, obstinate from 'advices' to turn it off.

0

4 Answers 4

2

Try this..

 UIStatusBarStyle style=[[UIApplication sharedApplication] statusBarStyle]; 
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, but no difference. Again UIStatusBarStyleDefault instead of UIStatusBarStyleLightContent
This worked for us. (iOS 8.1+) Very handy for when you want to display an overlay UIWindow, but don't want to change the status bar style. Just return this value in the preferredStatusBarStyle override of your view controller.
2

Found my answer... If View controller-based status bar appearance is turned on you should get style like this:

[[[[UIApplication sharedApplication] keyWindow] rootViewController] preferredStatusBarStyle] 

And you should take into account such things as navigation/tab-bar controllers. If you have your own you can do the following things.

- (UIStatusBarStyle) preferredStatusBarStyle { return [[ self selectedViewController] preferredStatusBarStyle]; } 

for your subclass of tab-bar controller and

- (UIStatusBarStyle) preferredStatusBarStyle { return [[self visibleViewController] preferredStatusBarStyle]; } 

for tab-bar controller.

Comments

1

I was using an overlay UIWindow without knowing which view controller is currently responsible for the status bar style, and therefore couldn't use other solutions. What worked for me is

UIApplication.shared.keyWindow?.rootViewController? .childViewControllerForStatusBarStyle.preferredStatusBarStyle 

What the documentation says:

Called when the system needs the view controller to use for determining status bar style.

Comments

0

This worked for me, I wanted to use presentingViewController's StatusBar style,

- (UIStatusBarStyle) preferredStatusBarStyle { return [self.presentingViewController preferredStatusBarStyle]; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.