UIWebView的背景设置为Clear Color,但它不透明 [英] UIWebView background is set to Clear Color, but it is not transparent

查看:388
本文介绍了UIWebView的背景设置为Clear Color,但它不透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我有一个XIB与 UIWebView Alpha = 1.0 背景设置为清除颜色不透明。在这个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;
}

UIWebView 显示静态html:

 < html>< head>< / head>< body style = \ margin:0 auto; text-align:center; background-color:transparent; color:white\> ...< / body>< / html& 

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

任何线索?

解决方案


$ b

  [webView setBackgroundColor:[UIColor clearColor]]; 
[webView setOpaque:NO];


I'm developing an iOS 4 application using iOS SDK latest version and XCode 4.2.

I have a XIB with a UIWebView with Alpha = 1.0, Background set to Clear Color and Opaque is not set. On this XIB I setup an image as background with this code:

- (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;
}

The UIWebView is showing an static html:

<html><head></head><body style=\"margin:0 auto;text-align:center;background-color: transparent; color:white\">...</body></html>

On iOS 5 simulator, its background is transparent, but on an iOS 4 device is grey.

Any clue?

解决方案

Also set :

[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];

这篇关于UIWebView的背景设置为Clear Color,但它不透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆