+(UIColor*)GetColorFromCSSHex:(NSString *) hexColor{ // @"#FF3300"
if (hexColor == nil || [hexColor isEqualToString:@""]) {
return nil;
}
if ([hexColor length] != 7) {
return nil;
}
//扫描十六进制字符串
unsigned int red = 255, green = 255, blue = 255;
NSRange range;
range.length = 2;
range.location = 1;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];//扫描一个十六进制表示的无符号值且取出并转换成十进制存储在red中
range.location = 3;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green];
range.location = 5;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue];
return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green/255.0f) blue:(float)(blue/255.0f) alpha:1.0f];
}
+(UIColor*)GetColorFromHexnum:(NSInteger)hexColor //0xFF3300
{
Byte red = hexColor>>16;
Byte green = hexColor>>8;
Byte blue = hexColor;
return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green/255.0f) blue:(float)(blue/255.0f) alpha:1.0f];
}
if (hexColor == nil || [hexColor isEqualToString:@""]) {
return nil;
}
if ([hexColor length] != 7) {
return nil;
}
//扫描十六进制字符串
unsigned int red = 255, green = 255, blue = 255;
NSRange range;
range.length = 2;
range.location = 1;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];//扫描一个十六进制表示的无符号值且取出并转换成十进制存储在red中
range.location = 3;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green];
range.location = 5;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue];
return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green/255.0f) blue:(float)(blue/255.0f) alpha:1.0f];
}
+(UIColor*)GetColorFromHexnum:(NSInteger)hexColor //0xFF3300
{
Byte red = hexColor>>16;
Byte green = hexColor>>8;
Byte blue = hexColor;
return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green/255.0f) blue:(float)(blue/255.0f) alpha:1.0f];
}