UIimage更改TintColor颜色

赵景曜
2023-12-01
- ( UIImage *) tintImageWithColor:( UIColor *)tintColor
{
   
UIGraphicsBeginImageContextWithOptions ( self . size , NO , [[ UIScreen mainScreen ] 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;
}
 类似资料: