标签:
定义 #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; }
标签:
原文地址:http://www.cnblogs.com/TheYouth/p/5064888.html