Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an easier way to set the PreferredStatusBarStyle of my app?

I'm super unhappy with the way I've had to set the EFFING UIStatusBarStyle of my app for iOS 7. Essentially I've got a custom presenter that sets up the SlidingPanels navigation (hamburger menu). Inside the custom presenter I define a RootController, and this is where I'm confused/ticked off/annoyed... pick one. </rant>

Normally I would like to just do something like this and be done with it.

RootController = new UIViewController();

// this line won't work because PreferredStatusBarStyle is a Method Group and not a property WTF
RootController.PreferredStatusBarStyle = UIStatusBarStyle.LightContent; 

But there seems to be no way to cleanly set properties in iOS. Therefore I'm stuck with this ugliness.

RootController = new CustomUiViewController();

//.....

public class CustomUiViewController : UIViewController
{
    public override UIStatusBarStyle PreferredStatusBarStyle()
    {
        return UIStatusBarStyle.LightContent;
    }
}

Then in the ViewDidLoad() of every view, I have to call SetNeedsStatusBarAppearanceUpdate(), and this is absurd to me.

Is there a cleaner/easier way to set this?

One of the side affects of the above approach is when the app is first loading, the StatusBar is still "dark" and therefore you can't see the clock until after ViewDidLoad().

like image 945
Chase Florell Avatar asked Dec 02 '22 20:12

Chase Florell


1 Answers

Just add to your app's info.plist a couple keys:

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
like image 87
x2_ Avatar answered Apr 28 '23 13:04

x2_