簡體   English   中英

iOS:讀取帶有換行文字的RTF文件

[英]IOS: Reading RTF file with wrapping text

我用代碼讀取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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM