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.

Answers


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;">

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

webViewScroller.alpha = 0.3f;

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.


Need Your Help

objective-c++ Confusion

iphone xcode objective-c++

I have several small questions of what can be done in objective-c++

Pass selected item from drop down list to servlet in doPost method?

java jsp servlets

I am working with Servlet and JSP. I have a form in which I have a drop down list which is getting populated dynamically. Now once I have selected any items from that drop down list, I want to prin...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.