Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get HTML in UITextView

Tags:

ios

uitextview

I display html in UITextView by:

[self.textView setValue:@"<b>Content</b>" forKey:@"contentToHTMLString"];,

After editing content in UITextView, I want to get content include html so I use:

[self.textView valueForKey:@"contentToHTMLString"]; but app crash, how to fix it?

like image 527
Nhu Nguyen Avatar asked Sep 04 '13 07:09

Nhu Nguyen


1 Answers

For ios 7 use following code.

NSString *htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p><img src='http://blogs.babble.com/famecrawler/files/2010/11/mickey_mouse-1097.jpg' width=70 height=100 />";
        NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
        textView.attributedText = attributedString;
like image 140
Bhoopi Avatar answered Sep 18 '22 13:09

Bhoopi