I am making an app for iOS 9.1 (using Xcode 7.1 and Swift 2.0), which contains a UITextView
for displaying formatted text from an rtf resource file. I am calling the following function in the viewDidLoad()
function of the view controller to load the text:
func loadTutorialText() {
if let rtfPath = NSBundle.mainBundle().URLForResource("TutorialText", withExtension: "rtf") {
do {
let attributedStringWithRtf = try NSAttributedString(URL: rtfPath, options: [NSDocumentTypeDocumentAttribute : NSRTFTextDocumentType], documentAttributes: nil)
self.textView.attributedText = attributedStringWithRtf
} catch {
print("Error loading text")
}
}
}
When I run the app, the text from the rtf
resource file is loaded but everything is displayed as plain text. Here's an example of the test rtf
file I'm using:
Example Heading
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
Example Heading
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.
Bulleted List
- Item 1
- Item 2
- Item 3
Are there some properties I need to set for the UITextView
to display this properly?