Created
July 26, 2017 14:45
-
-
Save e23z/b99d8592c465e365b48ae7746f814ce9 to your computer and use it in GitHub Desktop.
[Tint Image in CALayer] How to tint an image that is in a CALayer object. #swift #mobile #ios #ui
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (UIImage *)tintedImageWithColor:(UIColor *)tintColor blendingMode:(CGBlendMode)blendMode highQuality:(BOOL) yerOrNo; | |
| { | |
| UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f); | |
| if (yerOrNo) { | |
| CGContextRef context = UIGraphicsGetCurrentContext(); | |
| CGContextSetShouldAntialias(context, true); | |
| CGContextSetAllowsAntialiasing(context, true); | |
| CGContextSetInterpolationQuality(context, kCGInterpolationHigh); | |
| } | |
| [tintColor setFill]; | |
| CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height); | |
| UIRectFill(bounds); | |
| [self drawInRect:bounds blendMode:blendMode alpha:1.0f]; | |
| if (blendMode != kCGBlendModeDestinationIn) | |
| [self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0]; | |
| UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext(); | |
| UIGraphicsEndImageContext(); | |
| return tintedImage; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment