Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using transparent background color in UIView by HTML code

I'm trying to display an ad in UIView... I need to set the background color to transparent... I tried using,

[viewObject setBackgroundColor:[UIColor clearcolor]]; 

Eventhough it made the UIView transparent, it is displaying white background...

Below is the HTML code I tried...

NSString *HTML = [NSString stringWithFormat:@"<html><head><meta name=\"viewport\" content=\"width=device-width, user-scalable=no\"/><style>*{margin:0px;padding:0px}</style>
</head><body style=\" background-color:transparent\"><div style=\"text-align: %@\">%@</div></body></html>",adAlignment,link]; 

Thanks in advance...

Regards,,

Suraj

like image 797
Suran Avatar asked Dec 29 '22 01:12

Suran


2 Answers

Did you also set opaque = NO; on the view?

like image 176
koregan Avatar answered Dec 31 '22 12:12

koregan


I'm not sure if I understood your question, but you should have a UIWebView for your HTML code. To implement a UIWebView with a transparent background all you need to do is

1) set the UIWebView's backgroundColor property to [UIColor clearColor]

2) use the UIWebView's content in the html:

3) the UIWebView's opaque property set to NO.

The above are taken verbatim from Apple's TransWeb sample code ReadMe.txt file.

like image 30
Nick Toumpelis Avatar answered Dec 31 '22 14:12

Nick Toumpelis