8

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?

Thanh-Nhon Nguyen
  • 3,402
  • 3
  • 28
  • 41
Nhu Nguyen
  • 874
  • 3
  • 18
  • 33

3 Answers3

28

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;
Bhoopi
  • 6,523
  • 3
  • 22
  • 16
3

According to Display html text in uitextview this question Use a UIWebView.

Because undocumented -[UITextView setContentToHTMLString:] method. App will be rejected for using undocumented methods.

But still you want doing this you can take a look this links Might be help:-

https://github.com/AliSoftware/OHAttributedLabel

https://www.cocoacontrols.com/controls/bctextview

https://www.cocoacontrols.com/controls/egotextview

and for doing this task with UIWebview you must look this :-

Rich-text-editing-sample-project

Community
  • 1
  • 1
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
-1
NSString *htmlContentString = self.compnayInfoPageDictionary[@"tDescription"];

[self.txtViewInfoPage setValue:htmlContentString forKey:@"contentToHTMLString"];
rpax
  • 4,468
  • 7
  • 33
  • 57
Chigs79
  • 162
  • 4