Clicky

iOS Dev Nugget 18 Handy macros for creating UIColor instances

.

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

Don't you wish it's easier to create UIColor instances?

#define MO_RGBCOLOR(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define MO_RGBCOLOR1(c) [UIColor colorWithRed:c/255.0 green:c/255.0 blue:c/255.0 alpha:1]
#define MO_RGBACOLOR(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

You use them like:

UIColor* quiteRed = MO_RGBCOLOR(250, 0, 0);
UIColor* grayish = MO_RGBCOLOR1(30);
UIColor* transparentBlue = MO_RGBACOLOR(0, 0, 200, 0.5);


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