Pages

Monday, August 12, 2013

Hex Color to UIColor in Xcode

How to use #FF00CC or 0xFF7620 kind of colors in UIColor, So here is the answer

First of all define a function in top, like below:


#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]


Then use this as below


self.logView.backgroundColor = UIColorFromRGB(0xee8029);


Reference Taken From:
http://stackoverflow.com/questions/1560081/how-can-i-create-a-uicolor-from-a-hex-string