-->

Using transparent background color in UIView by HT

2020-07-19 03:19发布

问题:

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

回答1:

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.



回答2:

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



回答3:

Your window color is white.clear this.

window.backgroundColor = [UIColor clearColor];