0
在我的應用程序中,我創建了一個PDF。我可以畫出單行字符串。但我想繪製一個字符串,多行。這裏是我的代碼將NSString繪製到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
如何修改這個代碼來繪製多行字符串?