Monday, June 13, 2011

Create UIColor Using Hex RGB Values

UIColor doesn't provide in its methods a way to create a UIColor object if you provide a hexadecimal RGB value (i.e. #00FFEE).

The link below provides a fast and easy solution in the way of the following macro:

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]


This macro can be called like this:
UIColorFromRGB(0x00FFEE)

http://cocoamatic.blogspot.com/2010/07/uicolor-macro-with-hex-values.html

No comments:

Post a Comment