iPhone UiWebView 带有绝对路径的图像
我在 UIWebView 中显示一些 html,并且在 html 中引用了图像,例如:“/images/test1.gif”等。
我以这种方式显示:
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[myWebView loadHTMLString:someHtml baseURL:baseURL];
我还将所有必需的图像添加到我的 Xcode 项目中,进入“图片目录。问题是,据我所知,baseUrl 以“/”结尾,图像路径以“/”开头(这是绝对的)。所有构成我图像的东西都不会出现。
我注意到,如果我在 html 中更改图像路径,例如“images/test.gif”,图像将会显示,但我希望(如果可能)避免更改 html 中的所有图像路径绝对到相对,因为这个html是从某个数据库导入的,如果再次导入,我将不得不再次更改它。
I display some html in my UIWebView and I have in my html references to images like: '/images/test1.gif' etc.
I display this in that way:
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[myWebView loadHTMLString:someHtml baseURL:baseURL];
I've also added all required images to my Xcode project, into 'images' directory. The problem is, that, as far as I can see, the baseUrl ends with '/', and path to the images starts with '/' (it's absolute). All that makes my images doesn't appear.
I've noticed, that if I change, in html, path to images, to for example 'images/test.gif', the image will show up, but I want (if possible) to avoid changing all image paths in html from absolute to relative, becasue this html is imported from some database, and in case of another import I would have to change it again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过从 baseURL 末尾剪掉斜线?我希望网络视图足够智能,可以在需要的地方添加斜杠,尽管盲目地连接两个字符串会产生双斜杠。
Have you tried clipping the slash from the end of baseURL? I should hope the web view is smart enough to add a slash where needed, despite blindly concatenating two strings that result in a double slash.