It's not so easy to get the separated Red Green Blue Alpha components from an UIColor.
But luckily you can use this helpful function.
You need:
- http://objective-c-functions.blogspot.com/2013/06/helpful-color-struct-rgb-hsv.html
/** Convert from UIColor to RGBA.
@param col UIColor to convert.
@return Returns RGBA color.
@see uicolorFromRgba:
*/
+ (COLOR_RGBA)rgbaFromUIColor:(UIColor *)col {
const CGFloat *components = CGColorGetComponents([col CGColor]);
COLOR_RGBA ret;
ret.r = components[0];
ret.g = components[1];
ret.b = components[2];
ret.a = components[3];
return ret;
}
Download the ready-for-use source file (.m) of Get RGBA components of UIColor
No comments:
Post a Comment