iOS中怎么将#35b665(16进制)的颜色值赋给image,请大神帮忙

从网络端获得的image是透明的,同时得到了一个#35b665(16进制)的值,怎么给image赋上这个值

1个回答

  • (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]; }
u014116643
mifit CGSize imageSize = CGSizeMake(50, 50);   UIGraphicsBeginImageContextWithOptions(imageSize, 0, [UIScreen mainScreen].scale);   [[UIColor colorWithRed:0 green:0 blue:0 alpha:1.0] set];   UIRectFill(CGRectMake(0, 0, imageSize.width, imageSize.height));   UIImage *pressedColorImg = UIGraphicsGetImageFromCurrentImageContext();   UIGraphicsEndImageContext();
4 年多之前 回复
u014116643
mifit 你想得到这个颜色值的图片吧?
4 年多之前 回复
u014116643
mifit 你想得到这个颜色值的图片吧?
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问