IOS: How to make UIWebView 50% transparent?

I want to create a UIWebView whose background is 50% transparent, but whose content, for example. not transparent at all.

Is it possible?

Thanks.

+4
source share
3 answers
webView.alpha=0.5f; [webView setBackgroundColor:[UIColor clearColor]]; [webView setOpaque:NO]; 
+11
source

Sounds like it's possible, maybe. See this blog post:

http://erikloehfelm.blogspot.com/2009/04/transparent-background-on-iphone.html

Creating a translucent background depends on whether you can set the CSS color of the BODY element of the web page in a translucent color (instead of "transparent").

In addition, this blog post does not show how to do this if you do not control the HTML page of the webpage you are trying to display, but it is possible that the UIWebView programmatically changes this color as soon as the contents of the page are loaded.

+2
source

Play with changing transparent to any color / alpha for webView.backgroundColor and html <body> css style to find the combination that you like best. Example with loadHTMLString :

 - (void)embedYouTubeWithVideoID:(NSString *)videoID { webView.backgroundColor = [UIColor clearColor]; CGFloat w = webView.frame.size.width; CGFloat h = webView.frame.size.height; NSString *ytUrlString = [NSString stringWithFormat:@"http://www.youtube.com/v/%@&version=3&autohide=1&autoplay=1&cc_load_policy=1&fs=1&hd=1&modestbranding=1&rel=0&showsearch=0", videoID]; NSString *embed = [NSString stringWithFormat:@"\ <html>\ <head>\ <meta name=\"viewport\" content=\"initial-scale = 1.0, user-scalable = no, width = %0.0f\"/>\ </head>\ <body style=\"background:transparent; margin-top:0px; margin-left:0px\">\ <div>\ <object width=\"%0.0f\" height=\"%0.0f\">\ <param name=\"movie\" value=\"%@\" />\ <param name=\"wmode\" value=\"transparent\" />\ <param name=\"allowFullScreen\" value=\"true\" />\ <param name=\"quality\" value=\"high\" />\ <embed src=\"%@\" type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowscriptaccess=\"always\" wmode=\"transparent\" width=\"%0.0f\" height=\"%0.0f\" />\ </object>\ </div>\ </body>\ </html>", w, w, h, ytUrlString, ytUrlString, w, h]; [webView loadHTMLString:embed baseURL:nil]; } 
0
source

All Articles