CaffeineShots
CaffeineShots

Reputation: 2162

how to set vibrancy value of UIVisualEffectView programmatically in swift?

I added visual effect view with blur to my viewController in StoryBoard from object library

enter image description here

then I get reference to it

 @IBOutlet weak var blurView: UIVisualEffectView

but I want to set its vibrancy from false to true programmatically

enter image description here

from image above below the blur Style I want to check or set to on the vibrancy programmatically. Could anyone help me? any suggestion would greatly appreciated.

Upvotes: 1

Views: 2141

Answers (1)

Chris Slowik
Chris Slowik

Reputation: 2879

It's the effect property. Not exactly a true/false, it takes a UIBlurEffect, or a UIVibrancyEffect. You can create a UIVibrancyEffect from a UIBlurEffect and assign that.

let blur = UIBlurEffect(style: .ExtraLight)
let vibrancy = UIVibrancyEffect(forBlurEffect: blur)

blurView.effect = vibrancy //with vibrancy
blurView.effect = blur //without vibrancy

Upvotes: 4

Related Questions