我有一个带有UIVisualEffectView的UIImage。我想让边缘更柔和,使其产生阴影效果。
我尝试使用maskToBounds
,但它并没有什么区别。
let weekndImage = UIImage(named: "weeknd.jpg")
let weekndIV = UIImageView(image: weekndImage)
weekndIV.frame.size = CGSize(width: 200, height: 200)
let blur = UIBlurEffect(style: .light)
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = weekndIV.bounds
weekndIV.addSubview(blurView)
weekndIV.layer.cornerRadius = 10
weekndIV.layer.masksToBounds = true
答案 0 :(得分:0)
在设置blurView框架之后和将blurView添加到weekndIV视图
之前移动这两行weekndIV.layer.cornerRadius = 10
weekndIV.layer.masksToBounds = true
答案 1 :(得分:0)
我认为您希望对视图产生阴影效果。为此,您可以从视图的shadowOpacity
访问shadowRadius
和layer
例如在 Swift 2 :
中class MyView : UIView {
override func awakeFromNib() {
layer.cornerRadius = 5.0
layer.shadowOpacity = 0.8
layer.shadowRadius = 5.0
layer.shadowOffset = CGSizeMake(2.0, 2.0)
}
}