如何在iphone中设置HTML页面的背景图像
问题描述:
在此先感谢您发送回答........ 我是iphone开发的初学者。如何在iphone中设置HTML页面的背景图像
我尝试了最后2天在iphone中设置UIWebView的背景图像,但我不能。 Becoze我不知道如何从项目目录中获取图像的正确路径和正确的语法。
答
使用此代码加载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];
希望这会有所帮助。
答
UIWebView显示HTML,要在Web视图中显示图像,您需要提供适当的HTML内容到loadHTMLString:baseURL:
或loadData:MIMEType:textEncodingName:baseURL:
。
答
- 创建一个UIImageView并加载图像。
- 创建一个UIWebView并将背景颜色设置为[UIColor clearColor]。
- 将UIWebView作为子视图添加到UIImageView。
我认为这是[UIColor clearColor] – NWCoder 2010-01-20 18:15:44
是的。谢谢。 :) – 2010-01-20 19:27:27