2011-05-18 5 views
1

Dans un WebView, je charge un fichier html. La page html est affichée avec un arrière-plan noir. Je veux qu'il soit semi-transparent. Si je mets setAlphaValue: alors la transparence du contenu webview change. Existe-t-il un moyen de définir (ou contrôler) la transparence de l'arrière-plan html.webview fond transparent

L'édition du fichier html serait la dernière option.

Répondre

2

Option 1: Modifier le code HTML ou CSS:

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

Option 2: Appliquer la transparence en utilisant JavaScript:

evaluateWebScript: 

EDIT

Snippet liés à deuxième 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 
+0

Pouvez-vous donner plus d'informations sur Option 2: – Raviprakash

+0

Exemple rapide ajouté. – Anne