How to blur an existing image in a UIImageView with Swift?

前端 未结 11 1940
自闭症患者
自闭症患者 2020-12-28 16:48

The setup is simple.

  • A ViewController with UIImageView that has an image assigned.
  • A UIButton that when clicked blurs the image in the UIImageView.<
11条回答
  •  旧巷少年郎
    2020-12-28 17:27

    You can add blur effect by UIBlurEffect and UIVisualEffectView:

    @IBAction func blur(_ sender: Any) {
    
        let darkBlur = UIBlurEffect(style: UIBlurEffectStyle.dark) 
        let blurView = UIVisualEffectView(effect: darkBlur)
        blurView.frame = bg_imagview.bounds
        blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        bg_imagview.addSubview(blurView)
    
    }
    

提交回复
热议问题