【问题标题】:UILabel not applying attributed text styles from RTFUILabel 未应用来自 RTF 的属性文本样式
【发布时间】:2014-07-12 04:01:29
【问题描述】:

我的项目中有一个 RTF 文件作为属性文本 (iOS 7) 加载到 UILabel 中。它显示为没有格式的纯文本。我认为这是一个字体问题,因为我在 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]];

error 为 nil,返回的 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}";
}

【问题讨论】:

  • > 我在 Xcode 中选择的字体不一定是 iOS 中的字体 是的。

标签: ios ios7 nsattributedstring


【解决方案1】:

如果我用只读的 UITextView 替换 UILabel ,它就可以工作。很奇怪,因为文档表明 UILabel 会正确执行此操作,但这是一个可行的解决方案。

【讨论】:

  • 但这不是解决问题的方法。你能告诉我一个完美的解决方法吗?
猜你喜欢
  • 2014-01-29
  • 1970-01-01
  • 1970-01-01
  • 2014-09-11
  • 2014-05-21
  • 1970-01-01
  • 2016-12-12
  • 2013-01-25
  • 2015-07-31
相关资源
最近更新 更多