UIView难度

时间:2012-06-08 05:05:17

标签: iphone ios xcode uiview

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

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 个答案:

答案 0 :(得分:1)

不要让您的视图透明,只需将其背景颜色设置为透明

像这样:

self.backgoundView.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:0.5];

答案 1 :(得分:1)

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

self.backgroundView.backgroundColor = [UIColor clearColor];
self.backgroundView.opaque = NO;

答案 2 :(得分:0)

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

干杯,

塔伦。

答案 3 :(得分:0)

self.backgroundView.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.5];
self.backgroundView.alpha = 1.0;