Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. //改变图片颜色
  2. - (UIImage *)imageWithColor:(UIColor *)color
  3. {
  4. UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
  5. CGContextRefcontext = UIGraphicsGetCurrentContext();
  6. CGContextTranslateCTM(context, 0, self.size.height);
  7. CGContextScaleCTM(context, 1.0, -1.0);
  8. CGContextSetBlendMode(context, kCGBlendModeNormal);
  9. CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
  10. CGContextClipToMask(context, rect, self.CGImage);
  11. [color setFill];
  12. CGContextFillRect(context, rect);
  13. UIImage*newImage = UIGraphicsGetImageFromCurrentImageContext();
  14. UIGraphicsEndImageContext();
  15. return newImage;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement