先谢谢你给我发回答........ 我是iphone开发的初学者。
我过去2天尝试在iphone中的UIWebView中设置背景图片。但我不能。 Becoze我不知道如何从项目目录和正确的语法中获取(正确的路径)图像。
答案 0 :(得分:2)
使用此代码加载带有背景图片的html。
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"bgfull.png"];
NSURL *url = [[NSURL alloc] initFileURLWithPath:path isDirectory:NO];
NSString *size = [@"100%25" stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *contentHtml = [NSString stringWithFormat:@"<html>\
<head>\
<style type=\"text/css\">\
html {height:%@;}\
body {height:%@; margin:0; padding:0; color:white; font-size:40px;}\
#bg {position:fixed; top:0; left:0; width:%@; height:%@;}\
#content {position:relative; z-index:1;}\
</style>\
</head>\
<body>\
<div id=\"bg\"><img src=\"%@\" width=\"%@\" height=\"%@\"></div>\
<div id=\"content\"><font color=\"#DAF899\" size=\"+4\"><b>%@</b></font><p>%@</p></div>\
</body>\
</html>", size, size, size, size, url, size, size, self.navigationItem.title, content];
[webView loadHTMLString:contentHtml baseURL:nil];
希望这有帮助。
答案 1 :(得分:1)
答案 2 :(得分:0)
UIWebView显示HTML,以便在网页视图中显示向loadHTMLString:baseURL:
或loadData:MIMEType:textEncodingName:baseURL:
提供正确HTML内容所需的图片。