【发布时间】:2012-06-06 15:01:25
【问题描述】:
是否可以将 UIWebView 的 baseURL 设置为 NSDocumentDirectory?如果是,如何做到这一点?
我要做的是在 /img src=""/ 标签中本地显示一些下载的图像。
提前感谢您的任何建议。
【问题讨论】:
是否可以将 UIWebView 的 baseURL 设置为 NSDocumentDirectory?如果是,如何做到这一点?
我要做的是在 /img src=""/ 标签中本地显示一些下载的图像。
提前感谢您的任何建议。
【问题讨论】:
你可以尝试做这个人所做的事情:UIWebView: Absolute path for images in app documents folder
基本上,它使用图像源的文档目录路径,而不是简单的 img src="image_name"
【讨论】:
要在 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/
【讨论】: