您的位置:首页 > 产品设计 > UI/UE

UIColor之【扩展:#FFFFFF ->UIColor】

2015-09-17 00:00 417 查看
+(UIColor*)colorWithHexString:(NSString *)hexColor{

if ([hexColor length] == 7 && [hexColor hasPrefix:@"#"]) {

unsigned int red, green, blue;
NSRange range;
range.length = 2;

range.location = 1;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]]scanHexInt:&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];
}
return [UIColor clearColor];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  IOS UIColor