从不同的基础资源加载图像到webview

发布于 2024-10-09 10:06:47 字数 285 浏览 0 评论 0原文

我正在实现一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

懷念過去 2024-10-16 10:06:47

如果您对来自服务器的图像使用完整的 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 the baseURL parameter, which is only used for resolving relative (partial) URLs.

酒与心事 2024-10-16 10:06:47

我认为您可以创建 UIView 类的两个实例,并在两个视图中添加 UIWebView

在第一个 Web 视图中显示来自资源的图像,在另一个 Web 视图中显示来自服务器的图像。

尝试一下看看是否有效。

I think you can create two instance of UIView class and add the UIWebView 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文