I'm using an UIWebView to load some HTML text from a plist.
I managed to make its background transparent using
webView.opaque = NO;
webview.backgroundColor = [UIColor clearColor];
but the content, which is the text loaded from the plist, is shown with a disturbing white background.
I'm loading it using
NSString *descr = [NSString stringWithFormat:@"<html><head><style> body{font-size:16; font-family: Helvetica; color: black;} strong{font-family: Arial; font-weight: bold; font-size:16} .bg{background:transparent;}</style></head><body><div class='bg'>%@</div></body></html>",[item valueForKey:@"description"]];
[webView loadHTMLString:descr baseURL:nil];
I've tried setting the .bg
class background color to rgba(255,0,0,0.0)
, but nothing worked.
Also tried setting webView.scrollView.backgroundColor : [UIColor clearColor];
Any advice on how to get the UIWebView's content background transparent?
try this !
[webView setOpaque:NO];
webView.bakgroundColor = [UIColor clearColor];
In XCode 6.x uncheck Opaque and change Background's opacity to 0% . I think other XCode versions will also work.
Your HTML body will still have a background color.
You need to add 'background-color:transparent;' to the body part of your CSS
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.