正常来说圆角阴影通过设置shadowColor
,shadowOffset
,shadowRadius
,cornerRadius
可以解决,但是UIVisualEffectView通过常规方式无法成功,经过多次尝试后得到以下方案:
let backView = UIVisualEffectView(effect:UIBlurEffect(style: .prominent))
view.addSubview(backView)
backView.frame = CGRect(x: 100, y: 100, width: 200, height: 200)
backView.layer.shadowColor=UIColor.black.cgColor
backView.layer.shadowOffset=CGSize.zero
backView.layer.shadowRadius=5
backView.layer.shadowOpacity=0.3
//必须先将contentView 设置圆角,原因未知
backView.contentView.layer.cornerRadius=20
backView.contentView.layer.masksToBounds = true
backView.subviews.forEach{ subView in
subView.layer.cornerRadius=20
subView.layer.masksToBounds = true
}