This might be only of academic interest, as you probably don't want to rely on an undocumented method, but the following implementation seems to work:
// This structure is returned by the (undocumened) componentRGBA
// method of UIColor. The elements are "float", even on 64-bit,
// so we cannot use CGFloat here.
struct rgba {
float r, g, b, a;
};
@interface UIColor (ComponentRGBA)
-(struct rgba) componentRGBA;
@end
@interface NSString (ComponentRGBA)
-(struct rgba) componentRGBA;
@end
@implementation NSString (ComponentRGBA)
-(struct rgba) componentRGBA
{
CIColor* ciColor = [CIColor colorWithString:self];
UIColor* uiColor = [UIColor colorWithCIColor:ciColor];
return [uiColor componentRGBA];
}
@end
I figured this out with the help of the sample project of your (now deleted)
question KVC: what does the 'componentRGBA' method do when setting a color property?. The key point was that (as one could see by
inspecting the stack backtrace) the componentRGBA
method is called via
objc_msgSend_stret()
, which means that it returns a struct
and not some id
.