Adding blur effect to background in swift

前端 未结 11 1808
鱼传尺愫
鱼传尺愫 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条回答
  •  有刺的猬
    2020-11-29 15:13

    @AlvinGeorge should just use:

    extension UIImageView{        
        func blurImage()
        {
            let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
            let blurEffectView = UIVisualEffectView(effect: blurEffect)
            blurEffectView.frame = self.bounds
    
            blurEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] // for supporting device rotation
            self.addSubview(blurEffectView)
        }
    }
    

    usage:

     blurredBackground.frame = self.view.bounds
     blurredBackground.blurImage()
     self.view.addSubview(self.blurredBackground)
    

提交回复
热议问题