⚠️注意
- 给
UIView
设置阴影时,如果UIView
设置了圆角,一定要把masksToBounds
设置为NO
,这时设置的阴影才会有效。
- 如果
UIView
设置了圆角,最好保证阴影的半径shadowRadius
跟UIView
设置圆角的半径一致;
示例代码如下:
self.customView.layer.cornerRadius = 8.0;
// 设置阴影一定要把masksToBounds/设置为NO
self.customView.layer.masksToBounds = NO;
//shadowColor阴影颜色
self.customView.layer.shadowColor = ColorSetWithAlpha(@"000000", 0.08).CGColor;
//shadowOffset阴影偏移
self.customView.layer.shadowOffset = CGSizeMake(0,0);
//阴影透明度
self.customView.layer.shadowOpacity = 0.8;
//阴影半径
self.customView.layer.shadowRadius = 8.0;