问题
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