Skip to content

Instantly share code, notes, and snippets.

@Janak-Nirmal
Forked from jdewind/gist:1204051
Created May 9, 2012 07:32
Show Gist options
  • Save Janak-Nirmal/2642693 to your computer and use it in GitHub Desktop.
Save Janak-Nirmal/2642693 to your computer and use it in GitHub Desktop.
Capture the entire contents of a UITableView or UIScrollView
static UIImage* CreateImageFromView(UITableView *view)
{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(view.contentSize.width, view.contentSize.height), NO, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect previousFrame = view.frame;
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.contentSize.width, view.contentSize.height);
[view.layer renderInContext:context];
view.frame = previousFrame;
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment