1

Is it possible to set the baseURL of a UIWebView to NSDocumentDirectory? If yes, how does one do that?

What I'm trying to do is to display some downloaded images locally in the /img src=""/ tag.

Thanks in advance for any suggestions.

4

2 回答 2

0

要在 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]]];

这应该在 UIWebView 中加载 YOUR_IMAGE.jpg 阅读更多来自 http://dblog.com.au/iphone-development/loading-local-files-into-uiwebview/

于 2012-06-06T15:05:29.423 回答
0

您可以尝试执行此人所做的操作:UIWebView: Absolute path for images in app documents folder

基本上,它使用图像源的文档目录路径,而不仅仅是 img src="image_name"

于 2012-06-06T15:31:38.530 回答