图片透明度设定


UIImage *image = [UIImage imageNamed:@"whiteMask"];

        image = [image maskImage:[[UIColor blackColor] colorWithAlphaComponent:0.71]];

        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];


#import <UIKit/UIKit.h>


@interface UIImage (Mask)


- (UIImage *)maskImage:(UIColor *)maskColor;


@end

#import "UIImage+Mask.h"


@implementation UIImage (Mask)


- (UIImage *)maskImage:(UIColor *)maskColor

{

    CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);

    

    UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);

    

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextTranslateCTM(context, 0, rect.size.height);

    CGContextScaleCTM(context, 1.0, -1.0);

    CGContextClipToMask(context, rect, self.CGImage);

    CGContextSetFillColorWithColor(context, maskColor.CGColor);

    CGContextFillRect(context, rect);

    

    UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();

    

    UIGraphicsEndImageContext();

    

    return smallImage;

}


@end



阅读更多
个人分类: 图层透明度
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

图片透明度设定

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭