Tarvo Mäesepp Tarvo Mäesepp - 1 month ago 17
Swift Question

Aspect fill blurry view

I created some pageController which is working but with one problem. I have background image and I've added blurry view to it. But it doesn't stretch with the image:

enter image description here

The way I created the blurry view is this:

let blurEffect = UIBlurEffect(style: .dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.frame

self.view.insertSubview(blurEffectView, at: 1)


I have tried to make image to aspect fill, aspect fit etc.. Nothing works.

Answer

Do like this:

let blurEffect = UIBlurEffect(style: .dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.bounds
self.view.insertSubview(blurEffectView, at: 1)