react-native-navigation的迁移库

UIImage+tint.m 798B

123456789101112131415161718192021222324252627282930
  1. #import "UIImage+tint.h"
  2. @implementation UIImage (tint)
  3. - (UIImage *)withTintColor:(UIColor *)color {
  4. UIGraphicsBeginImageContext(self.size);
  5. CGContextRef context = UIGraphicsGetCurrentContext();
  6. CGContextTranslateCTM(context, 0, self.size.height);
  7. CGContextScaleCTM(context, 1.0, -1.0);
  8. CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
  9. // draw alpha-mask
  10. CGContextSetBlendMode(context, kCGBlendModeNormal);
  11. CGContextDrawImage(context, rect, self.CGImage);
  12. // draw tint color, preserving alpha values of original image
  13. CGContextSetBlendMode(context, kCGBlendModeSourceIn);
  14. [color setFill];
  15. CGContextFillRect(context, rect);
  16. UIImage *coloredImage = UIGraphicsGetImageFromCurrentImageContext();
  17. UIGraphicsEndImageContext();
  18. return coloredImage;
  19. }
  20. @end