如何借助html代码在UIWebView上显示本地图像?

如何借助html代码在UIWebView上显示本地图像?,html,objective-c,ipad,Html,Objective C,Ipad,我试图在UIWebView上显示本地图像。此web视图是在本地使用HTML代码生成的。我正在使用以下代码: [htmlPage appendStringWithFormat:@"< img src=\"%@\" alt=\"image\" height=\"100\" width=\"100\"/>",[[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"]; [htmlPage appendStringW

我试图在
UIWebView
上显示本地图像。此web视图是在本地使用HTML代码生成的。我正在使用以下代码:

[htmlPage appendStringWithFormat:@"< img src=\"%@\" alt=\"image\" height=\"100\" 

width=\"100\"/>",[[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"];
[htmlPage appendStringWithFormat:@“,[[NSBundle mainBundle]路径资源:@“png”类型的“myImage”;

您需要使用

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:htmlString baseURL:baseURL];
然后您的HTML应该像这样引用图像:

body {
    background-image:url('img/myBg.png');
}
看看这个问题:非常感谢!我忘记了“URL路径”转换,我的图片没有显示。