我有一个UITableView
填充了一些数据的数据,但是由于它包含的数据比屏幕的可视区域多,所以我只设法获得了它的快照,我想知道是否还有其他方法可以获得pdf中的整个tableview快照..这是我尝试过的谢谢
- (IBAction)clickMe:(id)sender
{
UIView *viewToRender = self.myTableView;
CGPoint contentOffset = self.myTableView.contentOffset;
UIGraphicsBeginImageContext(viewToRender.bounds.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// KEY: need to translate the context down to the current visible portion of the tablview
CGContextTranslateCTM(ctx, 0, -contentOffset.y);
[viewToRender.layer renderInContext:ctx];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIImageView *myImage=[[UIImageView alloc]initWithImage:image];
UIGraphicsEndImageContext();
[self createPDFfromUIViews:myImage saveToDocumentsWithFileName:@"PDF Name"];
}
- (void)createPDFfromUIViews:(UIView *)myImage saveToDocumentsWithFileName:(NSString *)string
{
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, myImage.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[myImage.layer renderInContext:pdfContext];
// remove PDF rendering context
UIGraphicsEndPDFContext();
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:string];
NSLog(@"%@",documentDirectoryFilename);
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
}