Wednesday, March 17, 2010

Getting a screenshot of any View Programmatically

Place the code shown here in the main file of your view controller
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

Here foobar is considered the UIView subclass which has the screen to be captured in the screenshot.