0

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.

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.

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?

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>

1 Answers1

0

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

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

Stefan Salatic
  • 4,513
  • 3
  • 22
  • 30
  • Thnx for your answer Stefan! For the text this would solve my problem, but I really want a slideshow with the photos shown above the text. This slide show should scroll together with the text. I see it on almost every news app. Can I create a slide show in HTML? And be able to click it to get full screen photos? I am not a real HTML pro... Nor an objective-C pro as well I have to say to be honest. But I'm trying! :-) – Theo Verriet Apr 27 '15 at 17:30
  • Do you create the HTML as well? If you won't be changing the layout I believe the best solution (performance wise) would be to create a fully native views and just load up the images and text from JSON. So for example you would have a `UIPageViewController` as a header in `UITableView` and then display the other stuff in rows or something similar. – Stefan Salatic Apr 27 '15 at 18:59
  • I wouldn't recommend using a half native, half web solution. Either create a layout within the application as just load up the content in appropriate places, or go full web view, and spend a bit more time formating the HTML. I would advise that you go full native. That way you will learn iOS programming better and the performance will be way better. – Stefan Salatic Apr 27 '15 at 19:02