Search code examples
iosuikitios7statusbar

Getting current iOS 7 statusbar style


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.


Solution

  • 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.