1

I want to change the background color of the webview. Not for the HTML document it display but for the actual scroll view which can be scrolled. If you scroll a web view you see a gray background color. I have tried below code for this but not working for me. Actually I want to make it transparent.

    [detailWebV setOpaque:NO];
    detailWebV.backgroundColor = [UIColor clearColor];

Thanks in advance!

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Bharat Jagtap
  • 1,692
  • 2
  • 22
  • 35

3 Answers3

5

Try this

myWebView.opaque = NO;
myWebView.backgroundColor = [UIColor clearColor];
[myWebView loadHTMLString:
@"<html><body style='background-color: transparent'>
       Content Here</body></html>" baseURL:nil];
arclight
  • 5,299
  • 1
  • 22
  • 26
2

Another way is to set it by using JavaScript:

[yourWebView stringByEvaluatingJavaScriptFromString:@"document.body.style.background = '#000000';"];
Björn Kaiser
  • 9,882
  • 4
  • 37
  • 57
2

the following has worked for me . This is what I wanted , when I scroll down the web view , the background should be transparent .

     [webV setOpaque:YES];
     webV.backgroundColor = [UIColor clearColor];

Thank you all !!!

Bharat Jagtap
  • 1,692
  • 2
  • 22
  • 35