I have a UIWebView in my app which I want to use to display an image which will link to another url.
I'm using
<img src="image.jpg" /> to load the image.
The problem is that the image doesn't load (ie. it can't be found) even though it's added as a resource in my project and is copied into the bundle.
I've tried using NSBundle to get the full path of the image and using that and it still doesn't show up in the web view.
Any ideas?
After having read a couple of chapters in the iOS 6 Programming Cookbok and started to learn objective-c and iOS programming, I would just like to add, that if one is going to load resources from a custom bundle and use that in a web view, it can be accomplished like this:
Then, in your html you can refer to a resource using the "custom" bundle as your base path:
If you use relative links to images then the images won't display as all folder structures are not preserved after the iOS app is compiled. What you can do is convert your local web folder into a bundle instead by adding the '.bundle' filename extension.
So if you local website is contained in a folder "www", this should be renamed to "www.bundle". This allows the image folders and directory structure to be preserved. Then load the 'index.html' file into the WebView as an HTML string with 'baseURL' (set to www.bundle path) to enable loading relative image links.
I had a simmilar problem, but all the suggestions didn't help.
However, the problem was the *.png itself. It had no alpha channel. Somehow Xcode ignores all png files without alpha channel during the deploy process.
Use this:
try use base64 image string.
In Swift 3:
This worked for me even when the image was inside of a folder without any modifications.