IOS:读取带有换行文本的RTF文件



我读取rtf文件的代码:

NSURL *rtfString = [[NSBundle mainBundle]URLForResource:@"Privacy Policy Imaspanse" withExtension:@"rtf"];
NSError *error;
NSMutableAttributedString *stringWithRTFAttributes = [[NSMutableAttributedString alloc]initWithFileURL:rtfString options:@{NSDocumentTypeDocumentAttribute : NSRTFTextDocumentType} documentAttributes:nil error:&error];
if (error) {
    NSLog(@"Error: %@", error.debugDescription);
} else {
    self.textLabel.attributedText = stringWithRTFAttributes;
}
self.scrollView.contentSize = [stringWithRTFAttributes size];

问题是长行不能换行到下一行。我怎样才能实现它?我需要的文本将是屏幕宽度和最大高度

试试这个

self.textLabel.attributedText = stringWithRTFAttributes;
[self.textLabel setNumberOfLines:0];
[self.textLabel sizeToFit];
[self.textLabel setLineBreakMode:NSLineBreakByWordWrapping];

最新更新