如何将JSON传递的HTML文本处理为格式化的UITextView [英] How to process JSON-deliverd HTML-text into formatted UITextView

查看:190
本文介绍了如何将JSON传递的HTML文本处理为格式化的UITextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建我的第一个IOS应用,并在创建视图时遇到问题.该应用程序显示我从JSON文件获取的信息. JSON包含HTML样式的格式化文本.在此html文本中,有一张或多张照片.在应用程序中,我希望这些照片显示在文本上方(每张照片显示几秒钟).这些照片也是JSON中的单独项目,因此我真的不需要HTML文本中的引用.我希望照片和文字在屏幕上不适合的情况下可以滚动.

I'm trying to create my first IOS app and run into problems when creating the view. The app shows info that I get from a JSON file. The JSON contains formatted text in HTML style. Within this html text there are one or more photos. In the app I want these photos to be shown above the text (each photo shown for some seconds). The photos are separate items in the JSON as well so I really don't need the reference in the HTML text. I want the photo and the text to be scrollable in case it does not fit on the screen.

我尝试了以下操作:从HTML文本中删除href标记,并在UIWebView中显示该文本.在文本上方,我在UIImageView中显示了照片.文本可以立即滚动,但是照片总是可见的.

I've tried the following: Removed the href tags from the HTML text and shown the text in a UIWebView. Above the text I showed the photos in a UIImageView. The text was scrollable instantly, but the photos weer always visible.

所以现在我认为我应该使用UITextview.但是,如何获取HTML文本中的格式,并将其转移到格式化的UITextView中呢?还是我错过了什么?

So now I think I should use UITextview. But how do I get the formatting that's in the HTML text transferred to a formatted UITextView? Or am I missing something?

HTML文本看起来像这样:

The HTML text looks something like this:

<p>ik was de afgelopen dagen voor het eerst van mijn leven in de Duitse stad Keulen. Bepakt met een frisse blik zitten we nu in de ICE die ons terug brengt naar Amsterdam. Hoog tijd om die blik te delen!<br \/>\n<a href=\"http:\/\/www.blablablog.nl\/wp-content\/uploads\/IMG_8259.jpg\"><img src=\"http:\/\/www.blablablog.nl\/wp-content\/uploads\/IMG_8259.jpg\" alt=\"\"><\/a>&nbsp;<\/p>\n<p><b>De ICE<\/b><\/p>\n<p>Eerst maar &#8216;s beginnen met die hogesnelheidstrein. &nbsp; Hij stopt weinig en da&#8217;s een voordeel. De stoelen zitten lekker en er rijdt een bistrowagen mee, maar echt snelheid maken doet hij pas na Keulen dus als je net als ik onvoorbereid op dat moment wacht kom je bedrogen uit.<br \/>\n&nbsp;<a href=\"http:\/\/www.blablablog.nl\/wp-content\/uploads\/IMG_8248.jpg\"><img src=\"http:\/\/www.blablablog.nl\/wp-content\/uploads\/IMG_8248.jpg\" alt=\"\"><\/a>&nbsp;<\/p>\n<p><b>De inwoners<\/b>

推荐答案

您可以为此使用UIWebView并使用html字符串对其进行初始化.这样,一切都会自动得到照顾.

You can just use UIWebView for that and initialize it with the html string. This way everything is taken care of automatically.

如果正确设置HTML格式,则滚动不会出现问题.

If you format the HTML properly you won't have issues with scrolling.

这篇关于如何将JSON传递的HTML文本处理为格式化的UITextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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