Saturday, June 11, 2011

Show Local Image in UIWebView

In order to load an image from within the app into your UIWebview, the webview needs to have the correct base url.

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:htmlString baseURL:baseURL];


With the correct base url, the images can be loaded relatively with:



Or in CSS

.someBG {
    background: url(theImage.png);
}

Source: http://stackoverflow.com/questions/747407/using-html-and-local-images-within-uiwebview

Another way to load an image is to convert it to base64 in this post:

http://iphoneincubator.com/blog/windows-views/display-images-in-uiwebview

No comments:

Post a Comment