0

在我的应用程序中,用户可以将一些信息添加到他的列表中,最后他想通过电子邮件将该列表发送给其他人。我只是想知道如何导出该列表?是否可以将其导出为 pdf 或 txt 文件?!

4

2 回答 2

1

如果您正在搜索 iOS5,请检查此链接

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()]
于 2012-11-16T11:47:49.643 回答
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);
}
于 2012-11-21T17:49:12.183 回答