贡献作者 -【XJDomain】
博客XJ: https://my.oschina.net/shengbingli/blog
GitHub直播地址: https://github.com/lishengbing/XJDomainLive
使用:
createFrostBackground(img: imageV.image!,view: self.view)
方法:
extension ViewController { //创建毛玻璃效果的背景 func createFrostBackground (img:UIImage,view:UIView) { let w = self.view.frame.width let h = self.view.frame.height let blurImageView = UIImageView(frame: CGRect(x: -w/2,y: -h/2,width: 2*w,height: 2*h)) // let blurImageView = UIImageView(frame: CGRect(x: 0,y: 0,width: w,height: h)) //模糊背景是界面的4倍大小 blurImageView.contentMode = .scaleAspectFill blurImageView.image = img //创建毛玻璃效果层 let visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light)) as UIVisualEffectView visualEffectView.frame = blurImageView.frame //添加毛玻璃效果层 blurImageView.addSubview(visualEffectView) self.view.insertSubview(blurImageView,belowSubview: view) } }原文链接:https://www.f2er.com/swift/322521.html