iPhone
iPhone

Reputation: 4170

load locally stored image in UIWebView

My requirement is to load locally stored image in the UIWebView.

My code is as follows:

NSBundle *mainBundle = [NSBundle mainBundle];
    NSURL *homeIndexUrl = [mainBundle URLForResource:@"web" withExtension:@"html"];
    NSURLRequest *urlReq = [NSURLRequest requestWithURL:homeIndexUrl];
    [self.webView loadRequest:urlReq];

My html file is as follows:

<html>
  <body>
    <img src=“Initial.png”>
  </body>
</html> 

I have referred following links but I am not getting my ultimate output

link1 link2

Upvotes: 0

Views: 1157

Answers (1)

Teja Nandamuri
Teja Nandamuri

Reputation: 11201

This thing worked for me:

The image should not be in the xcassettes.

  NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageFileName ofType:imageFileExtension];
 NSString *imgHTMLTag = [NSString stringWithFormat:@"<img src=\"file://%@\" />", imagePath];
 NSURL *Url = [mainBundle URLForResource:@"img_icon" withExtension:@"png"];
[self.webView loadHTMLString:imgHTMLTag baseURL:Url];

Upvotes: 2

Related Questions