How to make a transparent UIWebView

Knodel picture Knodel · Sep 5, 2010 · Viewed 56.6k times · Source

I have an app with a UITableView and a corresponding detail view for each row. In the detail view I have to display some text and a background image (text is different for each row, but the image remains the same). The easiest way, in my opinion, is to put the text in an .rtf file and display it in a UIWebView. Then just put a UIImageView behind the UIWebView.

I've tried to set the UIWebView's opacity to zero in IB, but it didn't help.

Can you help me?

Answer

Ortwin Gentz picture Ortwin Gentz · Oct 14, 2010

I recommend:

webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];

(setting these properties in Interface Builder will work for iOS 5.0+, but for iOS 4.3 you must set the backgroundColor in code)

And include this into your HTML code:

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