Last active
June 29, 2017 11:29
-
-
Save PoomSmart/cbfb02fa71d9026d9726 to your computer and use it in GitHub Desktop.
Reversed function of -[UIImage _flatImageWithColor:] on iOS 7+
This file contains 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
#import <UIKit/UIKit.h> | |
@interface UIImage (FlatImageWithColor) | |
- (UIImage *)_flatImageWithColor:(UIColor *)color; | |
@end | |
@implementation UIImage (FlatImageWithColor) | |
- (UIImage *)_flatImageWithColor:(UIColor *)color { | |
UIImage *flatImage = nil; | |
CGSize imageSize = self.size; | |
CGFloat scale = self.scale; | |
UIGraphicsBeginImageContextWithOptions(imageSize, NO, scale); | |
if (UIGraphicsGetCurrentContext()) { | |
[color set]; | |
UIRectFill(CGRectMake(0, 0, imageSize.width, imageSize.height)); | |
[self drawAtPoint:CGPointZero blendMode:kCGBlendModeDestinationIn alpha:1.0]; | |
flatImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
if ([self _isResizable]) | |
flatImage = [flatImage resizableImageWithCapInsets:self.capInsets]; | |
if (self->_flipsForRightToLeftLayoutDirection) // iOS 9+ | |
flatImage = [flatImage imageFlippedForRightToLeftLayoutDirection]; | |
if ([self _vectorImageCGPDFPage]) { // ? | |
if (!self.imageOrientation) { | |
[self configureVectorImagePropertiesForImage:flatImage]; | |
[flatImage _setVectorImageFlatColor:color]; | |
return flatImage; | |
} | |
} | |
} | |
return flatImage; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment