I've got some HTML and some images in my iPhone app, arranged something like:
html/
foo.html
images/
bar.png
I can get bar.png
to appear in my UIWebView
a couple of different ways -- either loading foo.html
from an NSUrl
, and walking back up the directory tree from the html directory:
<img src="../images/bar.png"/>
or by loading foo.html
into a string, using loadHtmlString
, and using [[NSBundle mainBundle] bundleURL]
as the baseURL
:
<img src="images/bar.png"/>
Both of these are kind of clumsy, though -- in the first case, if I move HTML files around I have to rejigger all the relative paths, and in the second case, I have to ignore the actual path structure of the HTML files.
What I'd like to make work is this --
<img src="/images/bar.png"/>
-- treating the bundleURL
as the root of the "site". Is there any way to make this work, or am I doomed to have that translated into file:///images/bar.png
and have the file not found?