0
votes

I have an RTF file in my project loading into a UILabel as attributed text (iOS 7). It displays as plain text with no formatting. I assume it's a font issue since the fonts I choose in Xcode aren't necessarily the fonts in iOS. The font I want is Helvetica Neue or Helvetica. But no font or styling I choose is ever recognized.

RTF:

enter image description here

iPad screen shot:

enter image description here

Code:

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 is nil and the docAttributes coming back look correct:

{
  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}";
}
1
> the fonts I choose in Xcode aren't necessarily the fonts in iOS Yes, they are.NRitH

1 Answers

1
votes

If I replace the UILabel with a read-only UITextView it works. Very strange since the documentation indicates a UILabel will do this correctly, but it's a workable solution.