如何在ios标签中显示html格式的文本 [英] How to display html formatted text in ios label
问题描述
我想在IOS中的 UILabel
上显示 html 格式的文字。
I would like to display html formatted text on a UILabel
in IOS.
在Android中,它有像这样的 .setText(Html.fromHtml(somestring));
In Android, it has api like this .setText(Html.fromHtml(somestring));
< a href =https://stackoverflow.com/questions/3235131/set-textview-text-from-html-formatted-string-resource-in-xml>从XML格式的字符串资源中设置TextView文本
我想知道ios中有什么等价物?
I would like to know what / if there is an equivalent in ios?
我搜索和找到这个帖子:
I search and find this thread:
但它建议使用 UIWebView
。我需要在每个表格单元格中显示html格式的字符串,所以我认为每行1 webview
似乎有点重。
But it suggests using UIWebView
. I need to display html formatted string in each table cell, so I think have 1 webview
per row seems a bit heavy.
还有其他选择吗?
谢谢。
推荐答案
for Swift 2.0 :
var attrStr = try! NSAttributedString(
data: "<b><i>text</i></b>".dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil)
label.attributedText = attrStr
这篇关于如何在ios标签中显示html格式的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!