Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blur Effect using Swift language in iPhone

I've been trying to implement the blur effect using an UIImageView in xcode 6 (swift language), I'm trying to implement it so everything that is below the ImageView get blurred.

I cannot make it work, so I'm asking you guys from stack overflow to help me, please.

How can that be done?

the code I wrote so far is:


class blurImage: UIImageView {

    init(frame: CGRect) {
        super.init(frame: frame)

        var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
        var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)

    }

}

like image 813
Vladimir Avatar asked Dec 20 '22 14:12

Vladimir


1 Answers

You need to assign a frame to effect blur view and add it as subview

class blurImage: UIImageView {

init(frame: CGRect) {
    super.init(frame: frame)

    var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
    var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
    effectView.frame = frame
    addSubview(effectView)
}
 }
like image 170
Kuroro Avatar answered Dec 22 '22 04:12

Kuroro