1

I am programming in iOS7. In my app I am using a UIWebView to load static HTML files that are packaged with the app. I want to show images, also packaged with the app, in my HTML files, but can not find the magic combination to get the images to show when the HTML file is loaded.

I saw some information on base64, which I did not understand, but I would like to find a simple solution because there will be others beside myself writing most of the HTML files.

Below is the basic format of the HTML code I am using. I have tried all manner of “/“ modifiers to no avail, including the full path as listed in the File Inspector.

<img src=“data:/Supporting Files/Info/InfoRecycle.png">

Does anyone know how I get the image to show within the HTML file?

2 Answers2

1

Try putting the image in the same folder as your html file. Then reference it like this:

<img src="InfoRecycle.png">

See if that works.

Stepan Grigoryan
  • 3,062
  • 1
  • 17
  • 6
1

I finally got it to work! I found the key to the answer in this post. I guess I did not find it earlier because I was focused on iOS7: Using HTML and Local Images Within UIWebView

I had to make some modifications in my Xcode, so it now looks like this:

    //..Loads a Local HTML File
strHTML = @"Info";
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:strHTML ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[_infoWebView loadHTMLString:htmlString baseURL:baseURL];

My reference to the image in the HTML code is now as suggested above by Stepan Grigoryan.

<img src="InfoRecycle.png">
Community
  • 1
  • 1