0

在我使用 iOS 7.1 构建项目之前,我的代码运行良好。之前,文本正确显示在 PDF 页面上。

[strSomeText drawInRect:rectForText withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, mutParagraphStyle, NSParagraphStyleAttributeName, colorRed, NSForegroundColorAttributeName, nil]];

但是现在,格式化字典中的所有内容都被忽略了。PDF 文档显示默认字体和大小的黑色文本。

感谢您的回复。

4

2 回答 2

0

你可以试试这个:

UIGraphicsPushContext(ctx);

[strSomeText drawInRect:rectForText withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, mutParagraphStyle, NSParagraphStyleAttributeName, colorRed, NSForegroundColorAttributeName, nil]];

UIGraphicsPopContext();
于 2014-12-30T15:44:10.023 回答
0

我会尝试使用NSAttributedString并找出这是否有效。对于您的代码停止工作的原因,我没有充分的理由,但试试这个:

//    obviously these variables are examples, keep whatever variables you are using
UIFont *font = [UIFont fontWithName:@"whatever_font" size:16.0f];
NSParagraphStyle *paragraphStyle = [NSParagraphStyle defaultParagraphStyle];

NSDictionary *attributes = @{NSFontAttributeName : font, NSParagraphStyleAttributeName : paragraphStyle, NSForegroundColorAttributeName : [UIColor redColor]};

NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:exampleString attributes:attributes];

[attributedString drawInRect];
于 2014-04-06T12:27:23.527 回答