2

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?

Phillip
  • 4,276
  • 7
  • 42
  • 74
  • possible duplicate of [UIWebView background is set to Clear Color, but it is not transparent](http://stackoverflow.com/questions/8667150/uiwebview-background-is-set-to-clear-color-but-it-is-not-transparent) – Arasuvel Sep 14 '15 at 06:44

3 Answers3

12

try this !

[webView setOpaque:NO];
webView.bakgroundColor = [UIColor clearColor];
1

In XCode 6.x uncheck Opaque and change Background's opacity to 0%. I think other XCode versions will also work.enter image description here

Pyae Thu Aung
  • 303
  • 1
  • 3
  • 10
0

Your HTML body will still have a background color.

You need to add 'background-color:transparent;' to the body part of your CSS

See here: https://stackoverflow.com/a/3935033/78496

Community
  • 1
  • 1
chedabob
  • 5,835
  • 2
  • 24
  • 44