I have the following test code:
CGFloat endRed, endGreen, endBlue, endAlpha;
[[UIColor greenColor] getRed:&endRed green:&endGreen blue:&endBlue alpha:&endAlpha];
that I call inside drawRect method for an UIView class. This code fails with exception
2011-11-06 02:29:28.671 Chartous[13457:b303] -[UICachedDeviceRGBColor getRed:green:blue:alpha:]: unrecognized selector sent to instance 0x4e7ea10
2011-11-06 02:29:28.673 Chartous[13457:b303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICachedDeviceRGBColor getRed:green:blue:alpha:]: unrecognized selector sent to instance 0x4e7ea10'
What is wrong here?
Try another approach:
const CGFloat* components = CGColorGetComponents([[UIColor greenColor] CGColor]);
CGFloat red = components[0];
CGFloat green = components[1];
CGFloat blue = components[2];
CGFloat alpha = CGColorGetAlpha([[UIColor greenColor] CGColor]);
This method is available in ios5 and later only. Are you running it on an earlier iOS version on the simulator or device? I assume so given the tag on your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With