我有两个兄弟视图:一个灰色标签和一个绿色按钮,按钮在下面。出于某种原因,我需要设置label.backgroundColor
为清除颜色并设置label.layer.backgroundColor
为灰色。按钮颜色为绿色。我希望在屏幕上看到灰色(因为标签位于按钮顶部)。但我看到的只是绿色(按钮的颜色)。为什么?
编辑:相关代码
// in my custom cell
-(void)awakeFromNib
{
[super awakeFromNib];
// customize label
_label.layer.cornerRadius = 5;
_label.layer.backgroundColor = [UIColor grayColor].CGColor;
_label.backgroundColor = [UIColor clearColor];
_label.layer.masksToBounds = NO;
// customize button
// show shadow and rounded corner at the same time
_button.backgroundColor = [UIColor clearColor];
_button.layer.backgroundColor = [UIColor greenColor].CGColor;
_button.layer.masksToBounds = NO;
_button.layer.cornerRadius = 10.0f;
self.layer.masksToBounds = NO;
self.layer.cornerRadius = 10.0f;
self.layer.shadowOpacity = 0.5f;
self.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:_button.bounds cornerRadius:10.0f].CGPath;
self.layer.shadowOffset = CGSizeMake(0.0f, 4.0f);
self.layer.shadowRadius = 2.0f;
}