swift shadow 设置阴影注意事项: 父类视图及自身属性masksToBounds 为false
extension UIView {
/// 设置阴影
/// - Parameters:
/// - color: 阴影颜色
/// - offset: 阴影偏移量
/// - opacity: 阴影透明度
/// - radius: 阴影半径
func addShadow(color: UIColor, offset:CGSize, opacity:Float, radius:CGFloat) {
self.masksToBounds = false
self.layer.shadowColor = color.cgColor
self.layer.shadowOffset = offset
self.layer.shadowOpacity = opacity
self.layer.shadowRadius = radius
}
}
关于shadowOffset阴影左右上下偏移量,平常开发过程中,总是拿不准。eg: layer.shadowOffset = CGSize(width: 10, height: 10)
width : 为正数时,向右偏移,为负数时,向左偏移
height : 为正数时,向下偏移,为负数时,向上偏移
截屏2020-08-03 下午5.06.37.png
网友评论