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 2.0 Improving Our User Interface Changing the Background Color

Adam Beck
Adam Beck
9,345 Points

Make sure you assign a UIColor instance representing blue color to the backgroundColor property of the backing view on U

Can anyone tell me why this is not working? It works in Xcode but no luck on challenge, I thought that's how you change the background color from the view?

colors.swift
class ViewController: UIViewController {

    override func viewDidLoad() {
        let blueColor = UIColor(red: 0/255.0, green: 0/255.0, blue: 225/255.0, alpha: 1.0)
        view.backgroundColor = blueColor
    }

    override func didReceiveMemoryWarning() {
        // Dispose of any resources that can be recreated
    }
}

1 Answer

Martin Wildfeuer
PLUS
Martin Wildfeuer
Courses Plus Student 11,071 Points

I am not sure what the problem is, your code looks just right.

This will pass

let blueColor = UIColor.blueColor()

and this will pass, although the color values should really be between 0 and 1.0, just as you did it. However, values greater than 1.0 will still evaluate to 1.0.

let blueColor = UIColor(red: 0, green: 0, blue: 255.0, alpha: 1.0)

So, to sum it up: your solution is correct and should pass.

Pasan Premaratne, could this be an issue with code check? Thanks!

Adam Beck
Adam Beck
9,345 Points

Passing the color works fine, but I get stuck when I try to apply it to the background. It gives me - "Make sure you assign a UIColor instance representing blue color to the backgroundColor property of the backing view on UIViewController."

Martin Wildfeuer
Martin Wildfeuer
Courses Plus Student 11,071 Points

Adam Beck You will pass the first challenge with your color, but assigning the color to the view will fail if it's not one of the above mentioned colors. It's not how you assign it to the view, because that's correct, it's the color itself. Give it a try and you will see.

Adam Beck
Adam Beck
9,345 Points

Thank you! Sorry, it definitely works when I changed my first answer. Appreciate the help!