简体   繁体   中英

How to put blur effect on image which is being used as background of table view in swift 2?

I tried but it's not working properly. Please give the correct solution for this.

I am calling this method setGradientBackground() inside viewDidload() method.

func setGradientBackground() {
  self.myTableView.backgroundColor = UIColor.clearColor()

  let image = UIImage(named: "r1")

  let imageview = UIImageView(image: image)

  imageview.frame = myTableView.bounds

  imageview.makeBlurImage(imageview)

 imageview.addSubview(myTableView) 

}

extension UIImageView {

  func makeBlurImage(targetImageView:UIImageView?){

     let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.ExtraLight)

     let blurEffectView = UIVisualEffectView(effect: blurEffect)

     blurEffectView.frame = targetImageView!.bounds

     blurEffectView.autoresizingMask = [.FlexibleWidth,.FlexibleHeight]      

     targetImageView?.addSubview(blurEffectView)
  }
}

You can use FXBlureView third party class.

https://github.com/nicklockwood/FXBlurView

You can set -

blurView.blurRadius = 18
blurView.tintColor = UIColor.blackColor()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM