Colors like white and black are represented using the monochrome color space (black/white, alpha) as opposed to (red, green, blue). An NSLog
of numComponents
would return 2
, so your if
block is never executed.
CGColorComponents return black (0, 0, 0) for UIColor whiteColor
-
30-08-2022 - |
Pergunta
If I run the following code:
CGColorRef cgcolor = [[UIColor whiteColor] CGColor];
int numComponents = CGColorGetNumberOfComponents(cgcolor);
CGFloat red = 0, green = 0, blue = 0;
if (numComponents >= 3)
{
const CGFloat *components = CGColorGetComponents(cgcolor);
red = components[0];
green = components[1];
blue = components[2];
}
An NSLog of red, green, and blue returns 0 for each; however, if I give it any other color, it displays the color I want it to display.
Why is this?
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow