图片透明度设定
2015-11-20 19:09
330 查看
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
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
相关文章推荐
- 如何查看端口占用情况
- MARKE下有用的IOS学习资料
- 谈一下OpenCV
- Ubuntu 14.04lts安装vncserver
- 最近学到的android资料
- 【Android】相机的简单调用
- XML的基础和DOCTYPE字段的解析
- 安装Ubuntu系统心得
- POJ2531Network Saboteur(DFS+剪枝)
- uva 327
- stand up meeting 11/20/2015
- ELK日志管理之——kibana部署
- AngularJS进阶(八)实现页面跳转并进行参数传递
- AngularJS进阶(八)实现页面跳转并进行参数传递
- libevent测试
- DRY 原则
- ELK日志管理之——kibana部署
- 阿里美团交恶,曾经情义今何在?
- c k e d i t o r
- Android app的文件缓存目录