改变图片的颜色,UIImage改变颜色

定义
#import <UIKit/UIKit.h>

@interface UIImage (ChangeImageColor)
/**
 *  改变图片的颜色
 *
 *  @param tintColor <#tintColor description#>
 *
 *  @return <#return value description#>
 */
- (UIImage *) imageWithTintColor:(UIColor *)tintColor;

@end

实现
- (UIImage *)imageWithTintColor:(UIColor *)tintColor{

    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
    [tintColor setFill];

    CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);

    UIRectFill(bounds);

    //Draw the tinted image in context
    [self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];

    UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return tintedImage;
}
将来的自己,会感谢现在不放弃的自己!
原文地址:https://www.cnblogs.com/TheYouth/p/5064888.html