+ (UIColor *) colorFromHexRGB:(NSString *) colorString
{
UIColor *result = nil;
unsigned int colorCode = 0;
unsigned char redByte, greenByte, blueByte;
if (nil != colorString)
{
NSScanner *scanner = [NSScanner scannerWithString:colorString];
(void) [scanner scanHexInt:&colorCode];
}
redByte = (unsigned char) (colorCode >> 16);
greenByte = (unsigned char) (colorCode >> 8);
blueByte = (unsigned char) (colorCode);
result = [UIColor
colorWithRed: (float)redByte / 0xff
green: (float)greenByte/ 0xff
blue: (float)blueByte / 0xff
alpha:1.0];
return result;
}
原文地址:http://blog.csdn.net/heyachaodeios/article/details/45245771