RGB与十六进制互转
http://tool.css-js.com/rgba.html
十六进颜色 (#03a9f4 0x050301)
+(UIColor *)becomeHexColor:(NSString *)hexColor
NSString *cString = [[hexColorstringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]]uppercaseString];
if ([cString length] < 6) return [UIColor blackColor];
if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2];
if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1];
if ([cString length] != 6) return [UIColor blackColor];
NSRange range;
range.location = 0;
range.length = 2;
NSString *rColorValue = [cString substringWithRange:range];
range.location = 2;
NSString *gColorValue = [cString substringWithRange:range];
range.location = 4;
NSString *bColorValue = [cString substringWithRange:range];
unsigned int r, g, b;
[[NSScanner scannerWithString:rColorValue] scanHexInt:&r];
[[NSScanner scannerWithString:gColorValue] scanHexInt:&g];
[[NSScanner scannerWithString:bColorValue] scanHexInt:&b];
UIColor *color = [UIColor colorWithRed:((CGFloat) r / 255.0f) green:((CGFloat) g / 255.0f) blue:((CGFloat) b / 255.0f) alpha:1.0f];
return color;
}