I have two sibling views: a gray label and a green button, button is underneath. For some reason, I need to set label.backgroundColor
to clear color and set label.layer.backgroundColor
to grey. And button color is green. I expect to see grey on screen (because label is on top of button). But all I see is green (color of button). Why?
EDIT: relevant code
// 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;
}