在我的申请中,我正在创建PDF。我能够绘制单行字符串。但我想绘制一个带有多行的字符串。这是我的代码
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filename = @"test.pdf";
NSURL *fileURL = [NSURL fileURLWithPathComponents:[NSArray arrayWithObjects:documentsDirectory, filename, nil]];
// Create PDF context
CGContextRef pdfContext = CGPDFContextCreateWithURL((CFURLRef)fileURL, NULL, NULL);
CGPDFContextBeginPage(pdfContext, NULL);
UIGraphicsPushContext(pdfContext);
// Flip coordinate system
CGRect bounds = CGContextGetClipBoundingBox(pdfContext);
CGContextScaleCTM(pdfContext, 1.0, -1.0);
CGContextTranslateCTM(pdfContext, 0.0, -bounds.size.height);
// String to show
NSString *strTest=[[NSString alloc]initWithFormat:@"%@\n%@", @"one",@"two"];
NSLog(@"%@", strTest);
// Drawing commands
[strTest drawAtPoint:CGPointMake(100, 100) withFont:[UIFont boldSystemFontOfSize:12.0f]];
// Clean up
UIGraphicsPopContext();
CGPDFContextEndPage(pdfContext);
CGPDFContextClose(pdfContext);
这是创建一个带有字符串的字符串的PDF。
One Two
但我想绘制字符串(两行字符串)
One
Two
如何修改此代码以绘制包含多行的字符串?