Skip to content

Instantly share code, notes, and snippets.

@PoomSmart
Last active June 29, 2017 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PoomSmart/cbfb02fa71d9026d9726 to your computer and use it in GitHub Desktop.
Save PoomSmart/cbfb02fa71d9026d9726 to your computer and use it in GitHub Desktop.
Reversed function of -[UIImage _flatImageWithColor:] on iOS 7+
#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