我嘗試在我的網頁視圖背景中顯示圖像,但我在裏面找到了一個藍色的矩形和一個訊問標記。我的代碼是這樣的:在網絡視圖中顯示圖像
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];
[webView loadHTMLString:myDescriptionHTML baseURL:nil];
我所有的文字顯示正確,除了background.png
。感謝名單爲幫助:)
編輯: 我已經試過這樣:
NSString* basePath = [[NSBundle mainBundle] bundlePath];
NSURL *url = [NSURL URLWithString:basePath];
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];
[webView loadHTMLString:myDescriptionHTML baseURL:url];
總是我得到了問號有:(
你應該接受的答案。 :) – Kjuly