Skip to content

Instantly share code, notes, and snippets.

@elnaqah
Created February 24, 2014 00:40
Show Gist options
  • Save elnaqah/9179668 to your computer and use it in GitHub Desktop.
Save elnaqah/9179668 to your computer and use it in GitHub Desktop.
load rtf file in UItextView
NSURL *rtfPath = [[NSBundle mainBundle] URLForResource: @"description_ar" withExtension:@"rtf"];
NSAttributedString *attributedStringWithRtf = [[NSAttributedString alloc] initWithFileURL:rtfPath options:@{NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType} documentAttributes:nil error:nil];
self.textView.attributedText=attributedStringWithRtf;
@sbporter
Copy link

sbporter commented Oct 7, 2016

Updates for Swift 3.0

if let rtfPath = Bundle.main.url(forResource: "filename", withExtension: "rtf") {
    do {
        let attributedStringWithRtf = try NSAttributedString(url: rtfPath, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes: nil)
        textView.attributedText = attributedStringWithRtf
    } catch {
        print("No rtf content found!")
    }
}

@Challenger34
Copy link

Good code. worked for me but I am unable to save images with NSTextAttachment. Please help.

@markst
Copy link

markst commented Jun 23, 2017

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment