Skip to content

Instantly share code, notes, and snippets.

@manishval
Created January 5, 2014 16:11
Show Gist options
  • Save manishval/8270078 to your computer and use it in GitHub Desktop.
Save manishval/8270078 to your computer and use it in GitHub Desktop.
UIImage form view
- (UIImage *)imageOfView:(UIView *)view
{
// This if-else clause used to check whether the device support retina display or not so that
// we can render image for both retina and non retina devices.
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
}
else
{
UIGraphicsBeginImageContext(view.bounds.size);
}
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment