+ (UIColor *)hexColor:(NSString *)hexColor{
if ([hexColor length] < 6) {
return nil;
}
unsigned int red,green,blue;
NSRange range;
range.length = 2;
range.location = 0;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];
range.location = 2;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green];
range.location = 4;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue];
return [UIColor colorWithRed:(float)(red/255.f) green:(float)(green / 255.f) blue:(float)(blue / 255.f) alpha:1.f];
}
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];
把你指定的range的子串取出来(应该是16进制格式的),转成10进制整数存到red变量里。