iOS UIView圆角和阴影不能共存问题处理

由于UIView分类中做的处理,同时设置了layer的cornerRadius和masksToBounds属性,影响了圆角和阴影共存,想要共存不能设置masksToBounds为YES。

- (void)setCornerRadius:(CGFloat)cornerRadius
{
    self.layer.cornerRadius = cornerRadius;
    self.layer.masksToBounds = YES;
}

修改为如下

xxxView.backgroundColor = [UIColor whiteColor];
xxxView.layer.cornerRadius = 3;
xxxView.layer.shadowOffset = CGSizeMake(0.0, 3.0);
xxxView.layer.shadowColor = [UIColor grayColor].CGColor;
xxxView.layer.shadowOpacity = 0.8; // 必传 默认是0.0

猜你喜欢

转载自blog.csdn.net/Mr17Liu/article/details/81535760