ios - 在 Web View 中显示图像
<p><p>我尝试在我的 webView 背景中显示图像,但里面有一个蓝色的小矩形和一个询问标记。我的代码是这样的:</p>
<pre><code>NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n"
"<head> \n"
"<style type=\"text/css\"> \n"
"body {font-family:helvetica; font-size:12;}\n"
"h2 {font-family:Times new roman;color: #105870}"
"</style> \n"
"</head> \n"
"<body><img src=\"background.png\" /><h2>Nom station</h2>%@<h2>Adresse</h2>%@<h2>Tél</h2>%@<h2>Sens de circulation</h2>%@<h2>Voie</h2>%@<h2>Station de lavage</h2>%@<h2>Commerce</h2>%@<h2>Distance</h2>%@<h2>Types de carburants</h2>%@</body>\n"
"</html>",leNomDeLaStation,adresseDeLaStation,telDeLaStation,circulationDeLaStation,voieDeLaStation,lavageDeLaStation,commerceDeLaStation,distanceDeLaStation,typesDeCarburantsDeLaStation];
;
</code></pre>
<p>除了 <code>background.png</code> 之外,我的所有文本都正确显示。感谢您的帮助:)</p>
<p><strong>编辑:</strong>
我试过这个:</p>
<pre><code>NSString* basePath = [ bundlePath];
NSURL *url = ;
NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> \n"
"<head> \n"
"<style type=\"text/css\"> \n"
"body {font-family:helvetica; font-size:12;}\n"
"h2 {font-family:Times new roman;color: #105870}"
"</style> \n"
"</head> \n"
"<body><img src=\"background.png\" /><h2>Nom station</h2>%@<h2>Adresse</h2>%@<h2>Tél</h2>%@<h2>Sens de circulation</h2>%@<h2>Voie</h2>%@<h2>Station de lavage</h2>%@<h2>Commerce</h2>%@<h2>Distance</h2>%@<h2>Types de carburants</h2>%@</body>\n"
"</html>",leNomDeLaStation,adresseDeLaStation,telDeLaStation,circulationDeLaStation,voieDeLaStation,lavageDeLaStation,commerceDeLaStation,distanceDeLaStation,typesDeCarburantsDeLaStation];
;
</code></pre>
<p>我总是在那里得到询问标记:(</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您需要在以下位置指定正确的 <code>baseURL</code>:</p>
<pre><code>;
</code></pre>
<p>否则 webView 将不知道在哪里寻找你的“相对”uris(不以 http://开头的那些)</p>
<p>试试这个:</p>
<pre><code>NSString* basePath = [ bundlePath];
];
</code></pre>
<p>编辑:仔细检查您的项目资源中是否包含 <code>background.png</code> 以及文件名是否正确。</p></p>
<p style="font-size: 20px;">关于ios - 在 WebView 中显示图像,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/6579109/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/6579109/
</a>
</p>
页:
[1]