Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIColor - getRed: ... - raises exception

Tags:

ios

ios4

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?

like image 657
Eugen Avatar asked Nov 06 '11 09:11

Eugen


2 Answers

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]);
like image 56
Odys Avatar answered Nov 06 '22 00:11

Odys


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.

like image 4
jrturton Avatar answered Nov 05 '22 23:11

jrturton