美文网首页
设置UIImageView半透明,子视图不透明

设置UIImageView半透明,子视图不透明

作者: ChardXu | 来源:发表于2016-09-12 14:16 被阅读633次

/** 设置图片透明度 */

+ (UIImage *)image:(UIImage*)image setAlpha:(CGFloat)alpha {

UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0f);

CGContextRef ctx = UIGraphicsGetCurrentContext();

CGRect area = CGRectMake(0, 0, image.size.width, image.size.height);

CGContextScaleCTM(ctx, 1, -1);

CGContextTranslateCTM(ctx, 0, -area.size.height);

CGContextSetBlendMode(ctx, kCGBlendModeMultiply);

CGContextSetAlpha(ctx, alpha);

CGContextDrawImage(ctx, area, image.CGImage);

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return newImage;

}

相关文章

网友评论

      本文标题:设置UIImageView半透明,子视图不透明

      本文链接:https://www.haomeiwen.com/subject/igknkttx.html