I want to show a local image in the webview , How to do ? somebody has a easy demo ? thanks a lot!!!
+5
A:
NSURL *imageURL = [NSURL fileURLWithPath:localImagePath];
NSURLRequest *request = [NSURLRequest requestWithURL:imageURL];
[[webView mainFrame] loadRequest:request];
Mike Abdullah
2009-01-21 11:32:03
Be sure to check if the webview is over 18 first, or you might get arrested!
Marc Charbonneau
2009-01-23 00:04:13
+4
A:
The best way to do is set the baseURL to the Bundles Path. Then from there you can call images from your Bundle like so:
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSURL *bundleBaseURL = [NSURL fileURLWithPath: bundlePath];
[webView loadHTMLString:htmlContent baseURL: bundleBaseURL];
The Image in your HTML can then call local images directly.
<img src="yourImageFromTheMainBundle.jpg" />
The same can be used to call CSS files or even JS files because the baseURL looks inside the main Bunble.
If its not in your main bundle, all you have to do is change the baseURL to the path of where the image is located.
Niels Hansen
2009-02-02 18:26:54