问题描述
- iOS中怎么将#35b665(16进制)的颜色值赋给image,请大神帮忙
-
从网络端获得的image是透明的,同时得到了一个#35b665(16进制)的值,怎么给image赋上这个值
解决方案
- (UIColor*) colorWithHex:(NSString *)hexValue alpha:(CGFloat)alphaValue
{
unsigned int red,green,blue;
NSRange range;
range.length = 2;
range.location = 0;
[[NSScanner scannerWithString:[hexValue substringWithRange:range]] scanHexInt:&red];
range.location = 2;
[[NSScanner scannerWithString:[hexValue substringWithRange:range]] scanHexInt:&green];
range.location = 4;
[[NSScanner scannerWithString:[hexValue substringWithRange:range]] scanHexInt:&blue];
return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green / 255.0f) blue:(float)(blue / 255.0f) alpha:alphaValue];
}
时间: 2024-10-04 17:10:21