1、十六进制颜色改为RGB颜色
+ (UIColor *)getRGBColorWithHexadecimalString:(NSString *)hexaDecimal
withAlpha:(CGFloat)alpha{
if (hexaDecimal.length > 6)
{
hexaDecimal = [hexaDecimal substringFromIndex:hexaDecimal.length - 6];
}
if (hexaDecimal
&& hexaDecimal.length == 6)
{
NSString *strOne
= [NSString stringWithFormat:@"%ld",strtoul([[hexaDecimalsubstringWithRange:NSMakeRange(0, 2)] UTF8String], 0, 16)];
NSString *strTwo
= [NSString stringWithFormat:@"%ld",strtoul([[hexaDecimalsubstringWithRange:NSMakeRange(2, 2)] UTF8String], 0, 16)];
NSString *strThree
= [NSString stringWithFormat:@"%ld",strtoul([[hexaDecimalsubstringWithRange:NSMakeRange(4, 2)] UTF8String], 0, 16)];
return RGB([strOne
floatValue], [strTwo floatValue], [strThree floatValue], alpha);
}
return RGB(255.0, 255.0, 255.0, 1.0);
}
2、RGB颜色转为十六进制
+ (NSString *)getHexadecimalStringWithRGBValue:(NSInteger)rgbValue{
if (rgbValue
> 255 || rgbValue < 0)
{
return @"00";
}
NSString *hexadecimalStr
= [[NSString stringWithFormat:@"%02lx",(long)rgbValue] uppercaseString];
return hexadecimalStr?hexadecimalStr:@"00";
}