Skip to content

Instantly share code, notes, and snippets.

@aspitz
Created August 21, 2013 13:19
Show Gist options
  • Save aspitz/6294359 to your computer and use it in GitHub Desktop.
Save aspitz/6294359 to your computer and use it in GitHub Desktop.
Category code to capture a UIView as a UIImage
#import "UIImage+UIViewCapture.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIImage (UIViewCapture)
+ (UIImage *)imageWithView:(UIView *)view{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment