参考 https://github.com/kballard/MGImageUtilities
- (UIImage *)imageTintedWithColor:(UIColor *)color
{
if (color) {
// Construct new image the same size as this one.
UIImage *image;
UIGraphicsBeginImageContextWithOptions([self size], NO, 0.0); // 0.0 for scale means "scale for device's main screen".
CGRect rect = CGRectZero;
rect.size = [self size];
// tint the image
[self drawInRect:rect];
[color set];
UIRectFillUsingBlendMode(rect, kCGBlendModeColor);
// restore alpha channel
[self drawInRect:rect blendMode:kCGBlendModeDestinationIn alpha:1.0f];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
return self;
}
本文介绍如何利用MGImageUtilities库中的(imageTintedWithColor:)方法为UIImage对象添加颜色渐变效果,具体步骤包括创建新图片、进行颜色渐变处理和恢复原始alpha通道。
2149

被折叠的 条评论
为什么被折叠?



