菜鸟教程小白 发表于 2022-12-11 20:03:30

html - 来自html字符串的iOS Swift 4图像未在WKWebView中加载


                                            <p><p>我在从 WKWebView 中的 html 字符串加载图像时遇到问题。在 UIWebView 中也不起作用。</p>

<p>html 字符串来自 API,我必须按原样显示内容,我无法控制标签或内容。
图像嵌入如下例所示。</p>

<pre><code>&lt;h2&gt;This is a heading&lt;/h2&gt;
&lt;a href=&#34;https://www.w3schools.com/w3css/img_lights.jpg&#34; title=&#34;&#34; class=&#34;colorbox&#34; data-colorbox-gallery=&#34;gallery-paragraphs_item-7725-ZrzXIAds_FA&#34; data-cbox-img-attrs=&#34; &amp;quot;&amp;quot;}&#34;&gt;&lt;/a&gt;
&lt;p&gt;This is a paragraph&lt;/p&gt;
&lt;p&gt;This is another paragraph&lt;/p&gt;
</code></pre>

<p>我尝试更改 info.plist 以启用应用程序传输安全设置,没有更改。
那里的所有示例都在 html 文本中带有标签,但是正如您在此处看到的,我必须从链接标签中显示它们。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>在<code><a></code>里面添加<code><Img></code>标签,像这样,</p>

<pre><code>&lt;h2&gt;This is a heading&lt;/h2&gt;
&lt;a href=&#34;https://www.w3schools.com/w3css/img_lights.jpg&#34; title=&#34;&#34; class=&#34;colorbox&#34; data-colorbox-gallery=&#34;gallery-paragraphs_item-7725-ZrzXIAds_FA&#34; data-cbox-img-attrs=&#34; &amp;quot;&amp;quot;}&#34;&gt;&lt;img alt=&#34;ImageName&#34; src=&#34;https://www.w3schools.com/w3css/img_lights.jpg&#34;&gt;&lt;/a&gt;
&lt;p&gt;This is a paragraph&lt;/p&gt;
&lt;p&gt;This is another paragraph&lt;/p&gt;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于html - 来自html字符串的iOS Swift 4图像未在WKWebView中加载,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/49900368/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/49900368/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: html - 来自html字符串的iOS Swift 4图像未在WKWebView中加载