UIWebView背景设置为"清除颜色",但它不透明

Van*_*nel 141 iphone cocoa-touch objective-c uiwebview ios

我正在使用iOS SDK最新版本和XCode 4.2开发iOS 4应用程序.

我有一个XIB,UIWebView其中Alpha = 1.0,背景设置为Clear Color,Opaque未设置.在这个XIB上,我使用以下代码将图像设置为背景:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"AboutBackground.png"]];
        self.view.backgroundColor = background;
        [background release];
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

UIWebView是否显示静态的html:

<html><head></head><body style=\"margin:0 auto;text-align:center;background-color: transparent; color:white\">...</body></html>
Run Code Online (Sandbox Code Playgroud)

在iOS 5模拟器上,它的背景是透明的,但在iOS 4设备上是灰色的.

任何线索?

Mau*_*lik 360

还设置:

[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];
Run Code Online (Sandbox Code Playgroud)

  • 这只适用于我在调用loadHTMLString后设置背景颜色和不透明度.似乎loadHTMLString重置这两个值. (3认同)

小智 15

     /*for ios please set this*/

     [webViewFirst setOpaque:NO];

     /*for html please set this*/
     <body style="background:none">
Run Code Online (Sandbox Code Playgroud)


Ele*_*gia 9

除了将webview的背景设置为清晰颜色外,还要确保将opaque设置为false.