关闭

图片透明度设定

154人阅读 评论(0) 收藏 举报
分类:


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



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:28374次
    • 积分:951
    • 等级:
    • 排名:千里之外
    • 原创:62篇
    • 转载:53篇
    • 译文:0篇
    • 评论:0条