【发布时间】:2014-02-01 22:57:15
【问题描述】:
这曾经可以工作,现在突然停止工作:
对于 iOS 7 iPad 应用,我使用
生成 PDFUIGraphicsBeginPDFContextToFile(pdfPathWithFileName, CGRectZero, nil);
...
UIGraphicsEndPDFContext();
在该代码块中,以下方法用于呈现带下划线的文本,但最近,它刚刚停止工作,并且根本不呈现传递给该方法的任何文本:
+(void)drawUnderlinedText:(NSString *)text withFont:(UIFont *)font andColor:(UIColor *)color andLocationX:(int)locationX andLocationY:(int)locationY andTextAreaWidth:(int)textWidth andTextAreaHeight:(int)textHeight{
NSDictionary *attributesDict;
NSMutableAttributedString *attString;
attributesDict = @{NSForegroundColorAttributeName : color, NSFontAttributeName : font, NSUnderlineStyleAttributeName : [NSNumber numberWithInt:NSUnderlineStyleSingle]};
attString = [[NSMutableAttributedString alloc] initWithString:text attributes:attributesDict];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGRect rect = CGRectMake(locationX, locationY, textWidth, textHeight);
[attString drawInRect:rect];
}
我在网上找不到任何关于绘制到 PDF 上下文的内容。有posts (and here) 提到了与标签有关的问题。但是生成PDF文件时似乎没有解决我的问题...
请帮忙!
【问题讨论】:
-
这是 iOS 7 中的一个错误。我遇到了同样的问题。如果属性字符串有任何带下划线的文本,它将不会出现在 PDF 中。我在 2 个月前提交了一份错误报告。
-
我的解决方法是删除所有下划线,以便至少显示其余文本。
-
好的,@rmaddy 我也提交了报告。
标签: ios pdf nsattributedstring underline