我想创建一个带有透明度和标签的UIView。
但我希望UILabel在最前面,就像这样:
如何实现?
以下是代码:
但我希望UILabel在最前面,就像这样:
如何实现?
以下是代码:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 200, 20)];
lbl.text = @"AAAAAA";
lbl.backgroundColor = [UIColor clearColor];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(50, 210, 230, 50)];
v.backgroundColor = [UIColor greenColor];
v.alpha = 0.5;
[v addSubview:lbl];
[self.view addSubview:v];
}
绿色视图的透明度为0.5,像文本一样,这是错误的!
谢谢。