1
votes

In a WebView i am loading html file.The html page is displayed with black background. I want it to be semitransparent. If I set setAlphaValue: then webview content transparency changes. Is there a way to set (or control) transparency of html background.

Editing html file would be last option.

1

1 Answers

2
votes

Option 1: Edit the HTML or CSS:

<body style="background-color: transparent">
body{background-color:transparent;}

Option 2: Apply the transparency using JavaScript:

evaluateWebScript:

EDIT

Snippet related to second option:

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