【发布时间】:2016-10-06 11:32:31
【问题描述】:
我的 iOS 应用程序将选定的联系人详细信息保存为 PDF 并在 WebView 中显示。
我的视图显示选定的联系人图像(在 UIImage 中)、姓名(在 UILabel 中)和电话号码等其他详细信息(在 UITableView 中) .
现在,我需要将此视图另存为 PDF 并在另一个视图中查看。
我现在使用的方法createPDFfromUIView 将我的视图保存为PDF。
但是我在我的 PDF 中看不到整个表格视图。
我需要滚动才能看到整个表格视图。
我该如何解决这个问题?
-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
// Creates a mutable data object for updating with binary data, like a byte array
NSMutableData *pdfData = [NSMutableData data];
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
UIGraphicsBeginPDFPage();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[aView.layer renderInContext:UIGraphicsGetCurrentContext()];
// remove PDF rendering context
UIGraphicsEndPDFContext();
// Retrieves the document directories from the iOS device
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}
【问题讨论】:
-
@New16 这仅包含一个 tableView。我还需要在另存为 pdf 之前合并一个标签和一个图像视图。我该怎么做?
-
取主
UIView的layer属性,它们是它们的一部分。
标签: ios objective-c uitableview pdf