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 Swift Debugging Our App Breakpoints

Tareq Yaghmour
Tareq Yaghmour
9,691 Points

application.setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false) - Deprecated in iOS 9, How to fix?

I'm using Swift 2 to build this App. and right now i'm getting this error on the AppDelegate.swift

setStatusBarStyle(':animated:') was deprecated in IOS 9.0: Use -[UIViewController preferredStatusBarStyle]

Anthony Babich
Anthony Babich
5,505 Points

I am wondering about this as well. I tried the answer below and tbh am not even really sure what changes it is making to the status bar. I have no errors with this answer below, but nothing changes?

I've inserted the code below on AppDelegate, right before return true. This worked.

application.statusBarStyle = .LightContent

3 Answers

Dennis Parussini
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dennis Parussini
Treehouse Project Reviewer

Sorry, was a little busy and made a mistake. Instead of calling the method on the view controller you should indeed call

application.statusBarStyle = .LightContent

in

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool

You also have to configure the info.plist to accept the changes. For this you go into info.plist and add a new Dictionary with

View controller-based status bar appearance and change the value to NO.

This way your status bar will be white no matter which view is on the screen.

Aubrey Taylor
Aubrey Taylor
2,991 Points

This method worked great for me. Thanks!

Dennis Parussini
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dennis Parussini
Treehouse Project Reviewer

Just call this method in any UIViewController.

override func preferredStatusBarStyle() -> UIStatusBarStyle {
        return UIStatusBarStyle.LightContent
    }

Hey Dennis, I've copied and pasted your code on the ViewController.swift. The status bar still stays black... Do I have to input anything on AppDelegate.swift? Thanks

mathewhucks
mathewhucks
2,156 Points

I've added this to my ViewController but nothing happens. The status bar is still black. Any idea why? :)

Josman Perez
Josman Perez
10,117 Points

Please be aware that you also have to modified the info plist in your project management, so

1) set

View controller-based status bar appearance to YES

2) override in your view controller (or in the views you want to have a light status bar) with:

override func preferredStatusBarStyle() -> UIStatusBarStyle { 
return UIStatusBarStyle.LightContent }