Adding blur effect to background in swift

前端 未结 11 2017
鱼传尺愫
鱼传尺愫 2020-11-29 14:50

I am setting a background image to view controller. But also i want to add blur effect to this background. How can I do this?

I am setting background with following

11条回答
  •  猫巷女王i
    2020-11-29 15:14

    In a UIView extension:

    func addBlurredBackground(style: UIBlurEffect.Style) {
        let blurEffect = UIBlurEffect(style: style)
        let blurView = UIVisualEffectView(effect: blurEffect)
        blurView.frame = self.frame
        blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        self.addSubview(blurView)
        self.sendSubviewToBack(blurView)
    }
    

提交回复
热议问题