0

I am trying to display local image onto the UIWebView. This web view is generated with HTML code locally. I am using the following code:

[htmlPage appendStringWithFormat:@"< img src=\"%@\" alt=\"image\" height=\"100\" 

width=\"100\"/>",[[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"];
1

1 Answer 1

2

You need to load your HTML into the webview with

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

Then your HTML should reference the image like so:

body {
    background-image:url('img/myBg.png');
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! I forgot about "Path to URL" transformation and my images was not shown.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.