Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView background is set to Clear Color, but it is not transparent

People also ask

What is clear color in Swift?

A color object with grayscale and alpha values that are both 0.


Also set :

[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];

     /*for ios please set this*/

     [webViewFirst setOpaque:NO];

     /*for html please set this*/
     <body style="background:none">

Besides setting your webview's background to clear color, also make sure that you set opaque to false.


webView.opaque = NO;

webView.backgroundColor = [UIColor clearColor];

You can try this code (i know, that it's unsafe, but it works even for ios5):

- (void)makeBodyBackgroundTransparent {
        for (UIView *subview in [webView subviews]) {
            [subview setOpaque:NO];
            [subview setBackgroundColor:[UIColor clearColor]];
        }
        [webView setOpaque:NO];
        [webView setBackgroundColor:[UIColor clearColor]];
}

NSString *content=@"example clear background color UIWebview";
NSString *style=[NSString stringwithformat:@"<html><head><style>body {background-color:transparent;}</style></head><body>%@</body></html>",content];
[myWebview loadhtmlstring:style baseurl:nil];