通过HTML代码在UIView中使用透明背景颜色

Sur*_*ran 4 html iphone objective-c uiview ipad

我正在尝试在UIView中显示广告...我需要将背景颜色设置为透明...我尝试使用,

[viewObject setBackgroundColor:[UIColor clearcolor]]; 
Run Code Online (Sandbox Code Playgroud)

虽然它使UIView透明,但它显示的是白色背景......

下面是我试过的HTML代码......

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]; 
Run Code Online (Sandbox Code Playgroud)

提前致谢...

问候,,

苏拉杰

kor*_*gan 5

你还在opaque = NO;视图上设置了吗?


Nic*_*lis 4

我不确定我是否理解你的问题,但你的 HTML 代码应该有一个UIWebView 。要实现具有透明背景的 UIWebView,您需要做的就是

1)设置UIWebView的backgroundColor属性为[UIColor clearColor]

2)在html中使用UIWebView的内容:

3)UIWebView的opaque属性设置为NO。

以上内容逐字摘自 Apple 的TransWeb示例代码 ReadMe.txt 文件。