UIimage更改TintColor颜色

来源:互联网 发布:冰点文库软件下载 编辑:程序博客网 时间:2024/06/08 05:02
- (UIImage*) tintImageWithColor:(UIColor*)tintColor
{
   
UIGraphicsBeginImageContextWithOptions(self.size,NO, [[UIScreenmainScreen]scale]);
   
CGContextRef context = UIGraphicsGetCurrentContext();
   
   
CGContextTranslateCTM(context,0,self.size.height);
   
CGContextScaleCTM(context,1.0, -1.0);
   
   
CGRect rect = CGRectMake(0,0,self.size.width,self.size.height);
   
   
CGContextSetBlendMode(context,kCGBlendModeNormal);
   
CGContextDrawImage(context, rect,self.CGImage);
   
   
CGContextSetBlendMode(context,kCGBlendModeSourceIn);
    [tintColor
setFill];
   
CGContextFillRect(context, rect);
   
   
UIImage *coloredImage = UIGraphicsGetImageFromCurrentImageContext();
   
UIGraphicsEndImageContext();
   
return coloredImage;
}
0 0
原创粉丝点击