如何在ios标签中显示html格式的文本 [英] How to display html formatted text in ios label

查看:1039
本文介绍了如何在ios标签中显示html格式的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在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:

如何在iPhone上显示来自API的HTML文本?

但它建议使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆