如何使UIImage边缘更柔和?

时间:2016-12-12 17:57:57

标签: ios swift uiimageview

我有一个带有UIVisualEffectView的UIImage。我想让边缘更柔和,使其产生阴影效果。

enter image description here

我尝试使用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

2 个答案:

答案 0 :(得分:0)

在设置blurView框架之后和将blurView添加到weekndIV视图

之前移动这两行
weekndIV.layer.cornerRadius = 10
weekndIV.layer.masksToBounds = true

答案 1 :(得分:0)

我认为您希望对视图产生阴影效果。为此,您可以从视图的shadowOpacity访问shadowRadiuslayer

例如在 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)
    }
}