mac osx,我想让我的webview看起来透明,并在其上显示数据,背景显示父视图的图像.
任何人都可以让我知道如何做到这一点?
这种方法不行
Nsstring * source = @"<html><head><title></title></head><body><div id=\"Box\">Example Box</div></body></html>";
[[webView mainFrame] loadHTMLString:source baseURL:[NSURL URLWithString:@""] ];
[[webView windowScriptObject] evaluateWebScript:@"document.getElementById('Box').style.backgroundColor = '#dddddd';"]; // Change Box background
[[webView windowScriptObject] evaluateWebScript:@"document.body.style.backgroundColor = '#dddddd';"]; // Change body background
解决方法
您需要在WebView上调用setDrawsBackground:并传入NO.这将阻止Web视图绘制背景,除非Web视图中加载的页面明确设置背景颜色.