我正在使用一个实例UIWebView来处理一些文本并正确地着色它,它将结果作为HTML而不是显示在UIWebView我希望Core Text用a 显示它NSAttributedString.
我能够创建和绘制NSAttributedString但我不确定如何将HTML转换并将HTML映射到属性字符串.
据我所知,在Mac OS X下NSAttributedString有一个initWithHTML:方法,但这只是Mac的补充,不适用于iOS.
我也知道有一个类似的问题,但它没有答案,我虽然我会再试一次,看看是否有人创造了一种方法来做到这一点,如果是的话,他们是否可以分享它.
我想在中显示带有<blockquote>标签的HTML文本UITextView.
HTML的例子:
<div>
<blockquote class="uncited">
<div>
<cite>Nick:</cite>
<blockquote class="uncited">
<div>
<cite>Tom:</cite>censored<br>
Hello
</div>
</blockquote>
<p>World</p>
</div>
</blockquote>
<p>Text</p>
</div>
Run Code Online (Sandbox Code Playgroud)
我使用以下代码在单元格中显示HTML文本:
UITextView *textView = (UITextView*)[cell viewWithTag:100];
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[thisComment.htmlText dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
textView.attributedText = attributedString;
Run Code Online (Sandbox Code Playgroud)
但UITextView它看起来像纯文本.我想得到它:样本
我该怎么做?我应该使用什么样的库?我想想HTML -> Markdown -> NSAttributedString -> TextView