Clicky

iOS Dev Nugget 49 Wrapper to Get UIColor Components

.

Need to run a code review on your codebase? Hire me

While working with UIColor instances, you might want to extract the individual red, green and blue components. UIColor provides the method -getRed:green:blue:alpha: to do this, but it's a little tedious. I wrote a few extensions methods that wraps around this so you can call -moComponents and get the components as an array or -moRed, -moGreen, -moBlue and -moAlpha separately,

UIColor* someColor; //Get the color from somewhere.
NSLog(@"Red: %f Green: %f Blue: %f alpha: %f", [someColor moRed], [someColor moGreen], [someColor moBlue], [someColor moAlpha]);

You can find the additions on github here and here.


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues