让UIWebView背景透明的方法,如下。

 

web_about.backgroundColor = [UIColor clearColor];

web_about.opaque = NO;

 

关键是在HTML里:

<body style="background-color: transparent">

 

//可以这样定义背景.

NSMutableString *string = [[[NSMutableString alloc] initWithString:htmlString] autorelease];

[string insertString:@"<body style=\"background-color:#FCF3E9;text-indent:2em;\">" atIndex:0];

[string appendString:@"</body>"];

NSLog(@"%@",string);

[webView loadHTMLString:string baseURL:nil];

 

#FCF3E9 可以通过取色器获得(该色为米黄色)

text-indent:2em 设置所有段落的首行缩进2格.

加载数据的时候,webView会显示一个白色的背景框,要去掉该框,我的做法是先将webView的frame设为Zero,在delegate的加载完成后再将frame设为原来大小.

 posted on 2010-11-17 16:40  Sure-G  阅读(1075)  评论(1编辑  收藏  举报