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 trialMichael Alford
3,809 PointssetStautsBarStyle: 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
8,227 PointsSo 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!
miikis
44,957 PointsIn 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
Courses Plus Student 391 PointsHi Keli, so...the didFinishLaunchingWithOptions end up like this?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
Abirbhav Goswami
15,450 PointsAbirbhav Goswami
15,450 PointsCouldn'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
8,227 PointsKeli'i Martin
8,227 PointsYou should be putting the snippet of code that I wrote above into your ViewController.m file.
Abirbhav Goswami
15,450 PointsAbirbhav Goswami
15,450 PointsI got that part. I know what overloading is. Just didn't know how it worked in Obj-C. Thanks anyway.
Keli'i Martin
8,227 PointsKeli'i Martin
8,227 PointsI guess I'm just not understanding your question then. Maybe these links from StackOverflow will help a little better.
http://stackoverflow.com/questions/19022210/preferredstatusbarstyle-isnt-called http://stackoverflow.com/questions/19108513/uistatusbarstyle-preferredstatusbarstyle-does-not-work-on-ios-7
Abirbhav Goswami
15,450 PointsAbirbhav Goswami
15,450 PointsOh 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
8,227 PointsKeli'i Martin
8,227 PointsOh, great! Glad to hear you got it working!