2016-09-16 56 views
0

我試過了,但無法正常工作。請爲此提供正確的解決方案。如何在swift 2中用作表格視圖背景的圖像上使用模糊效果?

我在viewDidload()裏面調用這個方法setGradientBackground()方法。

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) 
    } 
} 

回答