Skip to content

Instantly share code, notes, and snippets.

@aegzorz
Created May 30, 2012 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aegzorz/2837746 to your computer and use it in GitHub Desktop.
Save aegzorz/2837746 to your computer and use it in GitHub Desktop.
UIImage+Additions.h
typedef void (^UIImageDrawBlock)( CGContextRef ctx, CGRect rect );
@interface UIImage (Additions)
+ (UIImage*)imageWithSize:(CGSize)size opaque:(BOOL)opaque scale:(CGFloat)scale draw:(UIImageDrawBlock)draw;
@end
@implementation UIImage (Additions)
+ (UIImage*)imageWithSize:(CGSize)size opaque:(BOOL)opaque scale:(CGFloat)scale draw:(UIImageDrawBlock)draw
{
UIGraphicsBeginImageContextWithOptions( size, opaque, scale );
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect rect = CGRectMake( 0, 0, size.width, size.height );
CGContextClearRect( ctx, rect );
if( draw ) {
draw( ctx, rect );
}
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment