在 UIWebView 中加载本地存储的图像

load locally stored image in UIWebView

我的要求是在 UIWebView 中加载本地存储的图像。

我的代码如下:

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

我的html文件如下:

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

我已经参考了以下链接,但我没有得到我的最终输出

link1 link2

这个东西对我有用:

图像不应该在 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];