IOS中RGB字符串转UICOLOR

@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,UIColor,RGB字符串)