1

I have a UILabel attached to a UIScrollView. The Label is getting its attributed text from a .rtf(Rich Text File). The code I'm using to achieve this is:

    string =
    [NSAttributedString.alloc
     initWithFileURL:[ NSBundle.mainBundle URLForResource:@"fileName" withExtension:@"rtf"  ]
     options:nil
     documentAttributes:nil
     error:NULL
     ];

I am then passing the "string"(attributedString) to my UILabel like so

[self.Label setAttributedText:string];
self.Label.numberOfLines = 0;
self.Label.textAlignment = NSTextAlignmentCenter;
self.Label.font = [self.Label.font fontWithSize:(long)fontSize];

This all takes place in the ViewDidLoad.

My problem is that it takes a very long time to process this line: [self.Label setAttributedText:string]; Switching from one view to this view can take seconds.

Furthermore, when I try to change the font of the self.Label it takes a very long time as well.

I know the problem is with the UILabel processing the attributedString I'm just not sure why and how to fix it.

Important Note: The easy answer is use a UITextView, I don't want to because scrolling long non-english text in a UITextView is choppy and slow. Users have complained about it and after much research I've concluded that UILabel in a scrollView is the only way to achieve smooth scrolling for this application.

Nischal Hada
  • 3,230
  • 3
  • 27
  • 57
huddie96
  • 1,240
  • 2
  • 13
  • 26
  • Have you tried CoreText + NSAttributedString? – NightFury Jun 03 '15 at 05:13
  • @NightFury how is that done can you explain – huddie96 Jun 03 '15 at 12:21
  • See [this](http://www.raywenderlich.com/4147/core-text-tutorial-for-ios-making-a-magazine-app) tutorial and [this](http://stackoverflow.com/questions/3768801/can-i-use-nsattributedstring-in-core-text-in-ios) post. Hope it helps! – NightFury Jun 03 '15 at 12:46

0 Answers0