4

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().

Chase Florell
  • 46,378
  • 57
  • 186
  • 376
  • If you need the same statusbar style for the whole application check out [this question](http://stackoverflow.com/questions/19108513/uistatusbarstyle-preferredstatusbarstyle-does-not-work-on-ios-7). – x2_ Jan 19 '14 at 20:26
  • @x2_ That's the question I used to get my above code working. What might I be missing? – Chase Florell Jan 19 '14 at 20:28
  • Just add to your app's info.plist a couple keys: `UIViewControllerBasedStatusBarAppearance` `` `UIStatusBarStyle` `UIStatusBarStyleLightContent` – x2_ Jan 19 '14 at 20:35
  • Ah, that did it. I still had to set the UINavigationBar.Appearance, but at least it's clean now. – Chase Florell Jan 19 '14 at 21:16
  • @x2_ post it as an answer and I'll accept. – Chase Florell Jan 19 '14 at 21:38

1 Answers1

17

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

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
x2_
  • 349
  • 2
  • 10