正常來說圓角陰影通過設(shè)置shadowColor
,shadowOffset
,shadowRadius
,cornerRadius
可以解決揍魂,但是UIVisualEffectView通過常規(guī)方式無法成功舟舒,經(jīng)過多次嘗試后得到以下方案:
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 設(shè)置圓角,原因未知
backView.contentView.layer.cornerRadius=20
backView.contentView.layer.masksToBounds = true
backView.subviews.forEach{ subView in
subView.layer.cornerRadius=20
subView.layer.masksToBounds = true
}