Removing fixed text width from an RTF file loaded

2019-09-07 23:08发布

问题:

In my app I load the contents of an RTF file into a UITextView using this code:

NSURL *url = [[NSBundle mainBundle] URLForResource:[fileName stringByDeletingPathExtension] withExtension:[fileName pathExtension]];
NSError *error;
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithFileURL:url 
                                                                           options:@{NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType}  
                                                                           documentAttributes:nil  
                                                                           error:&error];

[textView setAttributedText:attributedString];

The problem I am having is that the width of the UITextView is greater than the text with of the rtf file. I want the text to fill the whole with of my UITextView. You can see the problem below in the screenshot.

Is there a way to make this this happen? Thanks a lot!