ryebread
ryebread

Reputation: 984

Unable to make a programmatically created UIWebView transparent

I am attempting to create a UIWebView programmatically, and I need it to be overlaid on another element, so I have the following in my code:

webViewScroller = [[UIWebView alloc] initWithFrame:CGRectMake(47, 80, 226, 310)];
webViewScroller.opaque = NO;
webViewScroller.backgroundColor = [UIColor clearColor];

The last two lines work great to make a transparent UIWebView when it is created in Interface Builder, but since I wanted to create and destroy the view strictly in code, I am creating it like this. I was expecting it to respond to the same setting parameters whether created in IB or in code. Am I missing something simple? I have also tried looping through subviews and making them transparent, but I didn't have any luck with that either. I am guessing that one of the parent views is not opaque, but I am not sure how to reference it to make it opaque. I tried this as well:

[webViewScroller.layer setOpaque:NO];

[Update:] I also added <body style="background-color:transparent;"> to my HTML. That is not the issue, as it was a parent containing view: the one behind the "shadows" when you scroll out of bounds.

Upvotes: 0

Views: 1090

Answers (3)

ryebread
ryebread

Reputation: 984

Just to close this question, I am answering it myself. I never found a solution to this particular issue, so I just created the WebView in IB, and it worked as was mentioned in my original post.

Thanks to all who tried to help.

Upvotes: 0

Jhaliya - Praveen Sharma
Jhaliya - Praveen Sharma

Reputation: 31722

Use below to make UIView inherited class as transparent. Set the Value of alpha as per your requirement.

webViewScroller.alpha = 0.3f;

Upvotes: 0

Morten Fast
Morten Fast

Reputation: 6320

You also need to set the HTML body's background color to transparent for this to work.

Something like this (or by using a style tag in the header):

<body style="background-color:transparent;">

Upvotes: 3

Related Questions