5

Is there an easy way to embed local images in an UIWebView? For example, I would want to embed an logo.png image in the UIWebView, which I've added to the Resources folder in Xcode. Would I simply add an img HTML tag for this?

openfrog
  • 40,201
  • 65
  • 225
  • 373
  • 1
    possible duplicate of [Using HTML and Local Images Within UIWebView](http://stackoverflow.com/questions/747407/using-html-and-local-images-within-uiwebview) – Ferruccio Jun 12 '12 at 14:35
  • you may refer to my answer on this post, hope it work for you [ http://stackoverflow.com/a/43011715/1316779 ](http://stackoverflow.com/a/43011715/1316779) – Amr Angry Mar 26 '17 at 09:40

1 Answers1

20

yes it's very simple but, for others, remember to put "file://" at the beginning of your path

for example:

NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"png"];
[myWebView loadHTMLString:[NSString stringWithFormat:@"<html><body><img src=\"file://%@\"></body></html>",path] baseURL:nil];
Robbbberto
  • 216
  • 2
  • 4