从不同的基础资源加载图像到webview
我正在实现一个 WebView,其中需要使用一些图像。为此,我使用资源文件夹下的图像并调用
[myWebView loadHTMLString:returnString baseURL:[[NSBundle mainBundle] resourceURL]];
它工作正常。同时我需要在同一个 WebView 中使用一些来自服务器的外部图像。为此,我需要更改目标服务器的 baseURL,但我不知道如何处理这两个。
如何在一个 HTML 中处理来自本地和外部服务器的图像?
I am implementing a WebView in which I need to use some images. For this, I use the images under the ressources folder and call
[myWebView loadHTMLString:returnString baseURL:[[NSBundle mainBundle] resourceURL]];
It is working fine. In the same time I need to use some external images coming from the server in the same WebView. For this I need to change the baseURL of the target server but I don't know how to handle these two.
How to handle both images, from local and external server in one HTML?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您对来自服务器的图像使用完整的 URL(即
http://www.exmaple.com/myimage.png
),它们将不会受到baseURL
的影响code> 参数,仅用于解析相对(部分)URL。If you use full URLs (i.e.
http://www.exmaple.com/myimage.png
) for the images coming from the server, they won't be affected by thebaseURL
parameter, which is only used for resolving relative (partial) URLs.我认为您可以创建
UIView
类的两个实例,并在两个视图中添加UIWebView
。在第一个 Web 视图中显示来自资源的图像,在另一个 Web 视图中显示来自服务器的图像。
尝试一下看看是否有效。
I think you can create two instance of
UIView
class and add theUIWebView
in both the views.In the first webview show the image from the resource and in the other webview show the image from the server.
Just give it a try see if this works.