-(IBAction)captureScreen:(id)sender
{
UIGraphicsBeginImageContext(foobar.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
}
Here foobar is considered the UIView subclass which has the screen to be captured in the screenshot.