Content" forKey:@"contentToHTMLString"]; , After...">

Get HTML in a UITextView

I display html in a UITextView by:

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

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

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

+8
ios uitextview
source share
3 answers

For ios 7, use the 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; 
+28
source share

According to Show html text in uitextview this question Use UIWebView .

Because the method is undocumented - [UITextView setContentToHTMLString:]. The application will be rejected for using undocumented methods.

But still you want to do this, you can take a look at these links. Maybe help: -

https://github.com/AliSoftware/OHAttributedLabel

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

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

and to complete this task using UIWebview you should see the following: -

Rich-text-editing-sample-project

+3
source share
 NSString *htmlContentString = self.compnayInfoPageDictionary[@"tDescription"]; [self.txtViewInfoPage setValue:htmlContentString forKey:@"contentToHTMLString"]; 
-one
source share

All Articles