0

我尝试添加一个像透明一样的白色视图,所以我设置了这个:

self.backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,0.0f,1024.0f,768.0f)];
[self.backgroundView setBackgroundColor:[UIColor whiteColor]];
[self.backgroundView setAlpha:0.5];
[self.backgroundView setOpaque:NO];
[self.view addSubview:self.backgroundView];


slotButton.frame = CGRectMake(550, 350, 400, 100);
[backgroundView addSubview:slotButton];
 }

但是当我在视图中添加一个按钮时,该按钮变得透明。我想要的是在不透明的情况下向白色透明视图添加一个按钮UIButton

4

4 回答 4

1

与其使您的 View 透明,不如仅将其背景颜色设置为透明

像这样:

self.backgoundView.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:0.5];
于 2012-06-08T05:08:17.710 回答
1

设置背景视图的 alpha 属性 < 1 会导致整个视图和内部的任何子视图(包括按钮)变得透明。如果您只希望视图的背景是透明的,请将视图的背景颜色设置为透明色。

self.backgroundView.backgroundColor = [UIColor clearColor];
self.backgroundView.opaque = NO;
于 2012-06-08T05:20:22.947 回答
0

这很简单。你需要有两个 UIView。在第二个视图上设置所有属性,如透明度、背景颜色或 Alpha,并将其添加到第一个视图上。现在在第一个视图上添加您的按钮。你完成了。

干杯,

塔伦。

于 2012-06-08T05:13:38.320 回答
0
self.backgroundView.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.5];
self.backgroundView.alpha = 1.0;
于 2012-06-08T05:49:01.703 回答