Iphone UIWebView';是否将s baseURL设置为NSDocumentDirectory?

Iphone UIWebView';是否将s baseURL设置为NSDocumentDirectory?,iphone,ios,Iphone,Ios,是否可以将UIWebView的baseURL设置为NSDocumentDirectory?如果是,如何做到这一点 我试图做的是在/img src=”“/标记中本地显示一些下载的图像 提前感谢您的建议。要在webview中加载本地文件,请执行以下操作 NSString *imagePath = [[NSBundle mainBundle] resourcePath]; imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/"

是否可以将UIWebView的baseURL设置为NSDocumentDirectory?如果是,如何做到这一点

我试图做的是在/img src=”“/标记中本地显示一些下载的图像


提前感谢您的建议。

要在webview中加载本地文件,请执行以下操作

NSString *imagePath = [[NSBundle mainBundle] resourcePath];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

NSString *HTMLData = @"
<img src="YOUR_IMAGE.jpg" alt="" width="100" height="100" />";

[webView loadHTMLString:HTMLData baseURL:[NSURL URLWithString: [NSString stringWithFormat:@"file:/%@//",imagePath]]];
NSString*imagePath=[[NSBundle mainBundle]resourcePath];
imagePath=[imagePath StringByReplacingOfString:@/“with字符串:@//”];
imagePath=[imagePath STRINGBYREPLACINGOURCRENCESOFSTRING:@“带字符串:@”%20“];
NSString*HTMLData=@”
";
[webView加载HTMLSTRING:HTMLData基URL:[NSURL URLWithString:[NSString stringWithFormat:@“文件:/%@/”,图像路径]];
这将在UIWebView中加载您的_IMAGE.jpg 阅读更多

你可以尝试做这个人所做的事情:


基本上,它使用文档目录路径作为图像源,而不仅仅是img src=“image\u name”

谢谢,但这不是我想要实现的,我不够具体。我想在本地HTML文件中显示NSDocumentDirectory中的图像,换句话说,将src=”“设置为用户文档目录中文件的路径。这能做到吗?