9

I'm using this code to create a blur effect inside my view:

let blur = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Light))
blur.frame = CGRectMake(180, 10, 200, 750)
myView.addSubview(blur)

is there any way to tweak the gaussian function producing the blur in order to achieve different level of "out of focus" effect?

Wolf
  • 9,679
  • 7
  • 62
  • 108
Claus
  • 5,662
  • 10
  • 77
  • 118

2 Answers2

1

Since there is no other parameter in UIBlurEffect , I think the only way is to use the CIFilter preset CIGaussianBlur to blur the background View and use its key inputRadius to adjust the level.
If you want to achieve the same effect as so called light/dark/ExtraLight, you can compose this filter with other filters.

duan
  • 8,515
  • 3
  • 48
  • 70
1

The radius of the actual UIBlurEffect cannot change, but there is a workaround.

Changing the alpha component of the UIVisualEffectView, will give a subtle blur effect.

let blur = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.Light))
blur.frame = CGRectMake(180, 10, 200, 750)
blur.alpha = 0.4
myView.addSubview(blur)

Swift 3

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.extraLight)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.alpha = 0.4
blurEffectView.frame = self.bounds
self.addSubview(blurEffectView)
Idan
  • 5,405
  • 7
  • 35
  • 52
  • 1
    Apple advises to not use the alpha value. an alpha value < 1 will make the actual (sharp) background visible and lays the blur ontop of it – Raildex Sep 02 '21 at 09:26