letsCode
letsCode

Reputation: 3064

UIBlurEffect not blurring entire image in UITableViewCell

I have the following code to blur out an image.

    let blurEffect = UIBlurEffect(style: .light)
    let blurredEffectView = UIVisualEffectView(effect: blurEffect)
    blurredEffectView.frame = imageBlur.bounds
    //blurredEffectView.alpha = 0.8
    imageBlur.addSubview(blurredEffectView)
    
    imageBlur.sd_setImage(with: URL(string: item._galleryURL), placeholderImage: UIImage(named: ""))

However, when I run the code, I am seeing this for the first two elements in the UITableView.

enter image description here

When I scroll down and then back up again, they will fix...

enter image description here

What can be causing this bug?

Upvotes: 0

Views: 49

Answers (1)

Alihan
Alihan

Reputation: 668

When you create the blur view in tableView cell you the view not now the exact size. So in the first create of screen it looks not okay but when you scroll down and up it recycles and know it size it becomes okay.

So you can solve it by giving size in layoutsubviews() function like

    override func layoutSubviews() {
    super.layoutSubviews()
    blurredEffectView.frame = imageBlur.bounds
}

Upvotes: 2

Related Questions