Displaying image in web view
i try to display image in my web view background, but i got little blue rectangle and an interrogation mark inside. My code is this:
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];
All my text is shown correctly except the background.png
. Thanx for help :)
EDIT : i have tried this :
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];
Always i got the interrogation mark there :(
You need specifying the correct baseURL
in:
[webView loadHTMLString:myDescriptionHTML baseURL:nil];
otherwise the web view will not know where to look for you "relative" uris (the ones that do not start with http://)
Try this:
NSString* basePath = [[NSBundle mainBundle] bundlePath];
[webView loadHTMLString:myDescriptionHTML baseURL:[NSURL fileURLWithPath:basePath]];
EDIT: double check that you included background.png
in the resources of your project and that the file name is correct.
i solved my issue, i have forgot the : fileURLWithPath:path
method
my code is this for any one who have problem with that :
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
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:baseURL];
精彩评论