ios - UILabel 不应用来自 RTF 的属性文本样式

标签 ios ios7 nsattributedstring

我的项目中有一个 RTF 文件作为属性文本加载到 UILabel 中(iOS 7)。它显示为纯文本,没有格式。我认为这是一个字体问题,因为我在 Xcode 中选择的字体不一定是 iOS 中的字体。我想要的字体是 Helvetica Neue 或 Helvetica。但我选择的字体或样式都未被识别。

RTF:

enter image description here

iPad 屏幕截图:

enter image description here

代码:

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/

相关文章:

ios - 使用firebase iOS swift创建具有相同捆绑ID的多个环境?

android - 如何处理播放指令

ios - 我怎样才能用带有 UILabel 的 NSAttributedString 进行描边和填充

ios - 从另一个类执行segue错误找不到segue

iphone - iPhone 5中的相机屏幕尺寸

ios - 使用 swift 在 ios7 上替代 QOS_CLASS_UTILITY

ios - CBCentral 连接到 CBPeripheral 无需扫描

UITextView 中的 iOS7 拼写检查错误

ios - 需要在 UILabel 的文本中获取多个@符号的 NSRanges 及其后面的文本

ios7 - NSTextAlignment Justified 在 iOS 7 中不起作用