您好我有一个能够打印UITableView的iOS应用程序。但是,仅打印显示的tableview的一部分。有没有办法打印整个tableview,即使它还没有被绘制?
以下是我用来打印的代码:
UIGraphicsBeginImageContext(self.mainTableView.contentSize);
[self.mainTableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIPrintInteractionController *printer = [UIPrintInteractionController sharedPrintController];
printer.printingItem = viewImage;
UIPrintInfo *info = [UIPrintInfo printInfo];
printer.printInfo = info;
UIPrintInteractionCompletionHandler completionHandler =
^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
if (!completed && error)
NSLog(@"FAILED! due to error in domain %@ with error code %u: %@",
error.domain, error.code, [error localizedDescription]);
};
UIButton * printButton = (UIButton *)sender;
if(UIUserInterfaceIdiomPad == [[UIDevice currentDevice] userInterfaceIdiom]){
[printer presentFromRect:printButton.frame inView:self.view animated:YES completionHandler:completionHandler];
} else {
[printer presentAnimated:YES completionHandler:completionHandler];
}
答案 0 :(得分:3)
关于这个问题有很多讨论。两个例子:
SO: Screenshot from a UITableView
SO: How to take an iPhone screenshot of entire view including parts off screen
问题是,UITableViews重用其单元格。 我认为最常见的方法是: