I changed the implementation of @fabian, because when calculating the size framethere is a problem using the automatic layout. When you try to read the framedata in init(), it has not been calculated correctly yet and has a size (1000,1000) for me, but should be (420,420). Therefore, you need to read and install later. For this I used layoutSubviews. Also, the settings frame = framedid not work, because it returns the absolute position of the container, but we need the window size.
class BluredImage: UIImageView {
var effectView:UIVisualEffectView!
required init(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)!
let blur:UIBlurEffect = UIBlurEffect(style: .light)
effectView = UIVisualEffectView (effect: blur)
addSubview(effectView)
}
override func layoutSubviews() {
super.layoutSubviews()
effectView.frame = bounds
}
}
source
share