+(UIColor *)colorWithR:(CGFloat)r g:(CGFloat)g b:(CGFloat)b a:(CGFloat)a{

    return [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a/100.0f];
} + (UIColor *)colorWithHexString:(NSString *)colorStr alpha:(CGFloat)alpha { //移除前缀
if ([colorStr hasPrefix:@"0X"] || [colorStr hasPrefix:@"0x"]) {
colorStr = [colorStr substringFromIndex:];
} if ([colorStr hasPrefix:@"#"]) {
colorStr = [colorStr substringFromIndex:];
} //判断长度
if (colorStr.length != ) {
return [UIColor clearColor];
} //提取值
NSRange range;
range.length = ;
//r
range.location = ;
NSString *rStr = [colorStr substringWithRange:range];
//g
range.location = ;
NSString *gStr = [colorStr substringWithRange:range];
//b
range.location = ;
NSString *bStr = [colorStr substringWithRange:range]; //转换值
unsigned int r, g, b;
[[NSScanner scannerWithString:rStr] scanHexInt:&r];
[[NSScanner scannerWithString:gStr] scanHexInt:&g];
[[NSScanner scannerWithString:bStr] scanHexInt:&b]; return [UIColor colorWithRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:alpha];
}
04-14 16:31