IOS:使用包装文本读取RTF文件

时间:2015-07-08 08:55:53

标签: ios textview uilabel uitextview 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];

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

1 个答案:

答案 0 :(得分:1)

试试这种方式

self.textLabel.attributedText = stringWithRTFAttributes;
[self.textLabel setNumberOfLines:0];
[self.textLabel sizeToFit];
[self.textLabel setLineBreakMode:NSLineBreakByWordWrapping];
相关问题