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

2016-09-12  本文已影响633人  ChardXu

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

+ (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;

}

上一篇 下一篇

猜你喜欢

热点阅读