在iOS中Android的Html.fromHtml()相当于什么? [英] What is the equivalent of Android's Html.fromHtml() in iOS?

查看:134
本文介绍了在iOS中Android的Html.fromHtml()相当于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Html 类中,Android有:

In the Html class, Android has:

public static Spanned fromHtml (String source)

根据文档

从提供的HTML字符串返回可显示的样式文本。

Returns displayable styled text from the provided HTML string.

..并将其与:

public void setText (CharSequence text, TextView.BufferType type)

根据 the TextView 文档


设置此TextView的文本display(参见
setText(CharSequence))并设置它是否存储在
样式/ spannable缓冲区中以及它是否可编辑。

Sets the text that this TextView is to display (see setText(CharSequence)) and also sets whether it is stored in a styleable/spannable buffer and whether it is editable.

..可以在TextView中显示带有HTML标记的字符串(例如此StackOverflow答案):

.. makes it possible to display a string with HTML markup in a TextView ( example from this StackOverflow answer ):

String styledText = "This is <font color='red'>simple</font>.";
textView.setText(Html.fromHtml(styledText), TextView.BufferType.SPANNABLE);

我的问题是 - 在iOS中与此相同的是什么?

My question is - what is the equivalent to this in iOS?

我做了一些研究,似乎人们推荐使用 UIWebView 为此目的 - 但这真的是唯一的解决方案吗?它是推荐的解决方案吗?

I have done some research, and it seems that people recommends using the UIWebView for this purpose - but is that really the only solution? And is it the recommended solution?

谢谢。

推荐答案

< a href =http://developer.apple.com/library/ios/ipad/#DOCUMENTATION/UIKit/Reference/UITextView_Class/Reference/UITextView.html\"rel =nofollow> Apple自己推荐,因此它必须是一个非常好的替代解决方案...

Apple itself recommends it, so it must be a quite good alternative solution...


要在应用程序中显示更复杂的样式,您需要使用UIWebView对象并使用HTML呈现您的内容。

To display more complex styling in your application, you need to use an UIWebView object and render your content using HTML.

如果你真的非常不想使用UIWebView,你可以使用 NSAttributedString 对象和渲染使用 OHAttributedLabel 的单行文字。

If you really, badly don't want to use UIWebView, you can use NSAttributedString objects and render one-line text using OHAttributedLabel.

这篇关于在iOS中Android的Html.fromHtml()相当于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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