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

Prapassorn Tinnabavorn
Prapassorn Tinnabavorn
3,528 Points

Should it be *blue: 1.0* or *blue: 255/255* instead of *blue: 255* ?

I thought the values couldn't go above 1.0 for UIColor :)

1 Answer

Jari Koopman
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jari Koopman
Python Web Development Techdegree Graduate 29,349 Points

Hi Prapassorn,

That's true unless you are a bit cheaty (like me) and create something like this:

extension UIColor {
    static func rgbColor(redValue: CGFloat, greenValue: CGFloat, blueValue: CGFloat, alpha: CGFloat) -> UIColor {
        return UIColor(red: redValue/255.0, green: greenValue/255.0, blue: blueValue/255.0, alpha: alpha)
    }
}

Which you can call as follows:

UIColor.rgbColor(redValue:255, greenValue:255, blueValue:255, alpha:1.0)

But that's not needed.

Hope this helped!

Regards, Jari