iOS在UIWebView中加载图像 [英] iOS Load Image in UIWebView

查看:191
本文介绍了iOS在UIWebView中加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拼命尝试通过UIWebView将如何将本地映像(保存在本地xcode包中)加载到以下HTML中。我已经花了无数小时跟随其他指南,但没有什么似乎工作,所有抛出错误。我试图在下面的NSString中添加一个本地图像,我在其中编写了IMAGEGOESHERE -

Desperately trying to figue out how to load a local image (saved in local xcode bundle) into the following HTML through a UIWebView. I have spent countless hours following other guides but nothing seems to work, all throw erros. Am trying to add a local image in the following NSString where I have written IMAGEGOESHERE -

{
    [super viewDidLoad];

    self.title = _restaurant.title;

    [[self navigationController] setNavigationBarHidden:NO animated:NO];

    self.activityIndicatorView.hidden = NO;
    [self.activityIndicatorView startAnimating];

    [self loadImageInNewThread];


    NSString *webViewContent = [NSString stringWithFormat:@"<html><head><style>* {font-family:   Helvetica}</style></head><body><center>%@ - %@<br><br><b>Restaurant:</b>%@</b><br>IMAGEGOESHERE<br></center></b></body></html>", _restaurant.openingTime,_restaurant.closingTime, _restaurant.name];

    [self.webView loadHTMLString:webViewContent baseURL:nil];
}

我希望你能帮助我驾驶我疯了!

I hope you can help as its driving me mad!

推荐答案

您需要先引用图片的路径:

You need to reference first the path of your image:

 NSString *pathImg = [[NSBundle mainBundle] pathForResource:@"yourimage" ofType:@"png"];

,然后在您的webViewContent中指定路径以及图片大小:

and then specify your path in your webViewContent along with the size of your image:

NSString* webViewContent = [NSString stringWithFormat:
                                   @"<html>"
                                   "<body>"
                                   "<img src=\"file://%@\" width=\"200\" height=\"500\"/>"
                                   "</body></html>", pathImg];

这篇关于iOS在UIWebView中加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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