Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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