我的项目中有一个 RTF 文件作为属性文本加载到 UILabel 中(iOS 7)。它显示为纯文本,没有格式。我认为这是一个字体问题,因为我在 Xcode 中选择的字体不一定是 iOS 中的字体。我想要的字体是 Helvetica Neue 或 Helvetica。但我选择的字体或样式都未被识别。
RTF:
iPad 屏幕截图:
代码:
NSError *error = nil;
NSURL *resourceURL = [[NSBundle mainBundle] URLForResource:@"terms-english" withExtension:@"rtf"];
NSDictionary *docAttributes = nil;
[self.termsLabel setAttributedText:
[[NSAttributedString alloc] initWithFileURL:resourceURL
options:nil
documentAttributes:&docAttributes
error:&error]];
错误为零,返回的 docAttributes 看起来正确:
{
BottomMargin = 72;
CocoaRTFVersion = "1265.21";
DefaultTabInterval = 36;
DocumentType = NSRTF;
HyphenationFactor = 0;
LeftMargin = 72;
PaperMargin = "UIEdgeInsets: {72, 72, 72, 72}";
PaperSize = "NSSize: {612, 792}";
RightMargin = 72;
TopMargin = 72;
UTI = "public.rtf";
ViewSize = "NSSize: {450, 420}";
}
最佳答案
如果我用只读 UITextView 替换 UILabel ,它就可以工作。非常奇怪,因为文档表明 UILabel 可以正确执行此操作,但这是一个可行的解决方案。
关于ios - UILabel 不应用来自 RTF 的属性文本样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24699613/