How to use an iPhone webView with an external HTML that references local images?

别等时光非礼了梦想. 提交于 2019-12-13 08:38:22

问题


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....

can i do this?

my html is something like this:

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

回答1:


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>


来源:https://stackoverflow.com/questions/2302213/how-to-use-an-iphone-webview-with-an-external-html-that-references-local-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!