Dynamic blur for UIView using UIVisualEffectView
- Put a transparent UIView over the elements that you need to blur (button, text field, etc.)
- Then initialize blur view:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var viewForBlur: UIView!
override func viewDidLoad() {
super.viewDidLoad()
self.viewForBlur.isUserInteractionEnabled = false;
_ = self.viewForBlur.blurView.setup(style: .light, intensity: 0);
}
}
- At any time you can change the blur intensity:
@IBAction func valueChanged(_ sender: Any) {
self.viewForBlur.blurView.intensity = CGFloat((sender as! UISlider).value);
}