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

Vansh Agarwal
PLUS
Vansh Agarwal
Courses Plus Student 3,965 Points

UIColor class declaration.

I thought that the RGB values that are passed when creating an instance of UIColor are supposed to be between 0 and 1 and that each value should be of type float. For example, for 200, you would have to pass in 200/255.0. But for this code challenge, the value 255 itself works instead of using (255/255). How?

Guilherme Ramos
Guilherme Ramos
8,287 Points

Did you used 200/255 or 200/255.0?

1 Answer

RGB Color mode uses the RGB model, assigning an intensity value to each pixel. In 8‑bits-per-channel images, the intensity values range from 0 (black) to 255 (white) for each of the RGB (red, green, blue) components in a color image. For example, a bright red color has an R value of 246, a G value of 20, and a B value of 50. When the values of all three components are equal, the result is a shade of neutral gray. When the values of all components are 255, the result is pure white; when the values are 0, pure black.

So you make colors with R#/255, G#/255, B#/255

UIColor(red: 56/255, green: 212/255, blue: 198/255, alpha: 1.0)