|
@@ -3,27 +3,14 @@
|
3
|
3
|
@implementation UIImage (tint)
|
4
|
4
|
|
5
|
5
|
- (UIImage *)withTintColor:(UIColor *)color {
|
6
|
|
- UIGraphicsBeginImageContext(self.size);
|
7
|
|
- CGContextRef context = UIGraphicsGetCurrentContext();
|
8
|
|
-
|
9
|
|
- CGContextTranslateCTM(context, 0, self.size.height);
|
10
|
|
- CGContextScaleCTM(context, 1.0, -1.0);
|
11
|
|
-
|
12
|
|
- CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
|
13
|
|
-
|
14
|
|
- // draw alpha-mask
|
15
|
|
- CGContextSetBlendMode(context, kCGBlendModeNormal);
|
16
|
|
- CGContextDrawImage(context, rect, self.CGImage);
|
17
|
|
-
|
18
|
|
- // draw tint color, preserving alpha values of original image
|
19
|
|
- CGContextSetBlendMode(context, kCGBlendModeSourceIn);
|
20
|
|
- [color setFill];
|
21
|
|
- CGContextFillRect(context, rect);
|
22
|
|
-
|
23
|
|
- UIImage *coloredImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
6
|
+ UIImage *newImage = [self imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
|
7
|
+ UIGraphicsBeginImageContextWithOptions(self.size, NO, newImage.scale);
|
|
8
|
+ [color set];
|
|
9
|
+ [newImage drawInRect:CGRectMake(0, 0, self.size.width, newImage.size.height)];
|
|
10
|
+ newImage = UIGraphicsGetImageFromCurrentImageContext();
|
24
|
11
|
UIGraphicsEndImageContext();
|
25
|
12
|
|
26
|
|
- return coloredImage;
|
|
13
|
+ return newImage;
|
27
|
14
|
}
|
28
|
15
|
|
29
|
16
|
@end
|