iOS Build a Simple iPhone App with Swift Improving Our User Interface Changing the Background Color

Vansh Agarwal
PRO
Vansh Agarwal
Pro 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)