When I call CGColorGetComponents
with the CGColor
returned from a UIColor
, it seems to work properly except with white and black.
Here's the code...
CGColorRef myColorRef = [[UIColor whiteColor] CGColor];
const CGFloat * colorComponents = CGColorGetComponents(myColorRef);
NSLog(@"r=%f, g=%f, b=%f, a=%f",
colorComponents[0],
colorComponents[1],
colorComponents[2],
colorComponents[3]);
This logs
r=1.000000, g=1.000000, b=0.000000, a=0.000000
Note both B and A are zero, not one.
If you substitute other colors like redColor, blueColor, etc., it works... the RGB and A values are set as one would expect. But again, black and white produce odd results. Is there some issue with this function or is there some workaround/task I should be doing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…