【发布时间】:2013-02-01 10:10:19
【问题描述】:
我创建了一个简单的UIWebview 控件,在其中我从 html 文件加载内容,但我想更改该 html 页面的背景而不是我的 web 视图。
对此有任何想法吗?
【问题讨论】:
我创建了一个简单的UIWebview 控件,在其中我从 html 文件加载内容,但我想更改该 html 页面的背景而不是我的 web 视图。
对此有任何想法吗?
【问题讨论】:
你有两个选择:
stringByEvaluatingJavaScriptFromString 调用它
示例JS函数:
function changeBackground(color){
document.getElementByName("body").style.background="#"+color;
}
示例ios调用代码:
[self.webView stringByEvaluatingJavaScriptFromString([NSString stringWithFormat:@"changeBackground(\"%@\");",yourColor];
【讨论】:
设置UIWebView背景颜色和不透明:NO
[webView setBackgroundColor:[UIColor clearColor]];
[webView setBackgroundColor:[UIColor purpleColor]];
[webView setOpaque:NO];
【讨论】:
你需要在 html body 设置背景颜色。
【讨论】: