I am added image to my application but I want to display them into my web view. I tried but not succeeded. how can I set the path for those images in html in image tag and how to display them.
Please help me out of this.
Thank you, Madan Mohan.
Are you just displaying the images individually or do you have an HTML file that references them?
To get a URL to the files directly:
NSString *pathForImage = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"];
NSURL *URL = [NSURL fileURLWithPath:pathForImage];
If you're loading an HTML file that references the images (such as by including an <img src="image.png">
, with no path info) then:
[webView loadHTMLString:htmlString
baseURL:[[NSBundle mainBundle] resourceURL]];
EDIT: so, supposing you had image.png in your application bundle as a resource, then you could do:
[webView loadHTMLString:@"<html><body><img src=\"image.png\"></body></html>"
baseURL:[[NSBundle mainBundle] resourceURL]];