在我的应用中,用户可以将一些信息添加到他的列表中,最后他想通过电子邮件将该列表发送给其他人。我只是想知道如何导出该列表?是否可以将其导出为pdf或txt文件?!
答案 0 :(得分:1)
如果您正在搜索iOS5,请检查this Link。
http://www.raywenderlich.com/6581/how-to-create-a-pdf-with-quartz-2d-in-ios-5-tutorial-part-1
编辑:像这样使用UI
elements
:
[yourView.layer renderInContext:UIGraphicsGetCurrentContext()]
答案 1 :(得分:1)
好吧我使用了这段代码,不幸的是我丢失了我找到答案的页面,很遗憾没有引用它。这是神奇的代码:
-(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, mainView.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[mainView.layer renderInContext:pdfContext];
// 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);
}