Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App with Objective-C Improving Our User Interface Using the ColorWheel Class

Michael Alford
Michael Alford
3,809 Points

setStautsBarStyle: is deprecated in iOS 9?

Hello,

In this video where we are setting the status bar on the iPhone to white. He uses a [application setStatusBarStyle:UIStatusBarStyleLightContent]; in the AppDelegate.m file. The warning I get that is not addressed in the video is 'setStatusBarStyle:' is deprecated: first deprecated in iOS 9 - Use -[UIViewController preferredStatusBarStyle]. Can someone explain what this exactly means and how I fix it. I have searched google and found [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; but that will give me the same answer.

3 Answers

Keli'i Martin
Keli'i Martin
8,227 Points

So basically, deprecated means that they have changed the way this is done in iOS 9. The suggestion given, using [UIViewController preferredStatusBarStyle], is the way it is done now. Unfortunately, the way that was presented can be a little misleading. In order to change the status bar style, you actually need to override the preferredStatusBarStyle method. You can do that by putting this code into your ViewController.m file:

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

Hope this helps!

Couldn't find info on this method in the docs. Thanks! I tried to implement it using self in viewController.m, like so:

[self preferredStatusBarStyle: UIStatusBarStyleLightContent];

Needless to say, that didn't work...

Keli'i Martin
Keli'i Martin
8,227 Points

You should be putting the snippet of code that I wrote above into your ViewController.m file.

I got that part. I know what overloading is. Just didn't know how it worked in Obj-C. Thanks anyway.

Oh you got me wrong. I was saying that I had tried doing it the other way, and couldn't figure out how to get it to work until I found your answer. It really helped.

Keli'i Martin
Keli'i Martin
8,227 Points

Oh, great! Glad to hear you got it working!

In addition to including the ViewController#preferredStatusBarStyle method — as described by Keli'i Martin above — you also need to make sure that the View controller-based status bar appearance property of your project is set to NO. This property is what allows the ViewController to change the color of the StatusBar instead of the AppDelegate doing it.

Jorge Hernández
PLUS
Jorge Hernández
Courses Plus Student 391 Points

Hi Keli, so...the didFinishLaunchingWithOptions end up like this?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    return YES;
}