Objective-c: How to display html

2020-06-29 02:52发布

I'm developing an iOS application for a news website, the application gets its JSON data from a url, the data is an HTML and sometimes has images embedded in them like this:

<div class="row ">some text here then <div class="col-xs-12 ">
<div class="col-sm-5 col-xs-12 pull-right">
<img src="image_url" /></div></div>

By far i know how to get only text (remove all html tags) but i don't know how to display the images that are embedded in that string.

Does anyone know how to do that ?

Note i researched a lot and didn't find a solution for this.

Thanks in advance.

3条回答
够拽才男人
2楼-- · 2020-06-29 03:06

Beside try

self.imageview1 = [UIImage  dataWithContentsOfURL@"http://www.fnordware.com/superpng/pnggrad16rgb.png"];
查看更多
何必那么认真
3楼-- · 2020-06-29 03:14

Try this code...

NSURL *url = [NSURL URLWithString:@"http://www.fnordware.com/superpng/pnggrad16rgb.png"];//This is Example url you can write your URL.

NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];

[self.imageview1 setImage:image];
查看更多
Evening l夕情丶
4楼-- · 2020-06-29 03:25

You could use the UIImageView+AFNetworking category. There is a method - (void)setImageWithURL:(NSURL *)url that will allow you set the image property on UIImageView with a url and asynchronous network call.

查看更多
登录 后发表回答