Skip to content

Instantly share code, notes, and snippets.

@iOSDigital
Created April 1, 2017 17:44
Show Gist options
  • Save iOSDigital/77f6652756cdc292a8ec4960658f55d8 to your computer and use it in GitHub Desktop.
Save iOSDigital/77f6652756cdc292a8ec4960658f55d8 to your computer and use it in GitHub Desktop.
invertedImageWithColor
-(UIImage *)invertedImageWithColor:(UIColor*)color {
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect contextRect = CGContextGetClipBoundingBox(context);
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, contextRect);
[self drawInRect:contextRect blendMode:kCGBlendModeDestinationOut alpha:1.0];
UIImage *invertedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return invertedImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment