查看与低alpha – 与高alpha的子视图
我有一个0.5的alpha的UIView
我已经添加了1的alpha的子视图。
子视图似乎inheritance父级的Alpha值。 有没有办法使子视图比其父视图更不透明?
代码如下所示:
CGRect promptFrame = CGRectMake(55, 80, 180, 50); UIView *inputPrompt = [[UIView alloc] initWithFrame: promptFrame]; [inputPrompt setBackgroundColor: [UIColor darkGrayColor]]; [inputPrompt setAlpha: .5]; inputPrompt.layer.cornerRadius = 8; inputPrompt.layer.masksToBounds = YES; CGRect fileTextFieldFrame = CGRectMake(10, 15, 150, 25); UITextField *filePrompt = [[UITextField alloc] initWithFrame: fileTextFieldFrame]; [filePrompt setBorderStyle:UITextBorderStyleRoundedRect]; [filePrompt setClearButtonMode:UITextFieldViewModeWhileEditing]; [filePrompt setBackgroundColor: [UIColor whiteColor]]; [filePrompt setAlpha: 1];
结果如下所示:
我希望能够看到灰色的UIView
下面的button,但不是在白色的UITextField
下面。 我该怎么做呢?
设置inputPrompt
的背景颜色的alpha不是直接的alpha。
[inputPrompt setBackgroundColor:[[UIColor darkGrayColor] colorWithAlphaComponent:0.5]]; //[inputPrompt setAlpha: .5];