如何使用带有引用本地图像的外部HTML的iPhone webView? [英] How to use an iPhone webView with an external HTML that references local images?

查看:127
本文介绍了如何使用带有引用本地图像的外部HTML的iPhone webView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我的web服务器上有一个外部html,这是我的iphone应用程序通过webview请求的......为了使页面加载更快,我想更改我的html以请求静态文件,如css和图像我的应用程序的本地资源文件夹....

Hi i have an external html on my webserver, that is requested by my iphone app through a webview... in order to make the page load faster, i want to change my html to request static files like css's and images from the local resource folder of my app....

我能做到这一点吗?

像这样:

my html is something like this:

<html> <body> 
<img
src="file://Resources/test.png">
</body> </html>


推荐答案

您可以将UIWebView的baseURL设置为资源路径您的主包:

You can set the baseURL for UIWebView to the resource path of your main bundle:

NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];

[webView loadHTMLString:htmlString baseURL:baseURL];

然后,您可以简单地引用您的图片,如下所示:

Then you can simply refer to your images like this:

<html> <body> 
<img src="test.png" />
</body> </html>

这篇关于如何使用带有引用本地图像的外部HTML的iPhone webView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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