Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cocoa: How to make background transparent webView?

Tags:

xcode

macos

cocoa

The mac osx ,I want to make my webview to look transparent and show the data on it with background showing images of parent view.

Can anyone please let me know how to do this? This method can not

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
like image 881
小弟调调 Avatar asked Apr 17 '12 01:04

小弟调调


Video Answer


1 Answers

You need to call setDrawsBackground: on the WebView and pass in NO. That will prevent the web view from drawing a background unless the page loaded in the web view explicitly sets the background color.

like image 134
Rob Keniger Avatar answered Oct 17 '22 18:10

Rob Keniger