@implementation NSString (getColor)
/**
例:NSString *colorString = @“FF0088”;
UIColor *color = [colorString getColor];
**/
-(UIColor *)getColor
{
unsigned int r,g,b;
NSRange range = NSMakeRange(0, 2);
NSString *string1 = [self substringWithRange:range];
[[NSScanner scannerWithString:string1] scanHexInt:&r];
range = NSMakeRange(2, 2);
string1 = [self substringWithRange:range];
[[NSScanner scannerWithString:string1] scanHexInt:&g];
range = NSMakeRange(4, 2);
string1 = [self substringWithRange:range];
[[NSScanner scannerWithString:string1] scanHexInt:&b];
return [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0];
}
@end
IOS中RGB字符串转UICOLOR
最新推荐文章于 2022-07-19 22:54:58 发布