在swift中设置模糊效果全屏

时间:2016-02-05 05:34:01

标签: ios swift uiblureffect

我想在全屏幕中设置模糊效果,就像应用

一样

这是我想要设置模糊效果的代码

 let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
 filePathToWrite1 = "\(paths)/\(videoTitle[a]).jpg"
 let img = UIImage(contentsOfFile: filePathToWrite1)
 viewImg.image = img

 let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
        blurEffectView = UIVisualEffectView(effect: blurEffect)
        blurEffectView.frame = viewImg.bounds
        blurEffectView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]

         viewImg.addSubview(blurEffectView)
         view.addSubview(viewImg)

这是img for my Original img

enter image description here

模糊效果

enter image description here

我想在下面 enter image description here

1 个答案:

答案 0 :(得分:0)

将此代码放在viewImg.image = img

viewImg.contentMode = .ScaleAspectFill