加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

【swift3.0】【毛玻璃效果】【简单粗暴的方法】

发布时间:2020-12-14 06:34:35 所属栏目:百科 来源:网络整理
导读:贡献作者 -【XJDomain】 博客XJ: https://my.oschina.net/shengbingli/blog GitHub直播地址 : https://github.com/lishengbing/XJDomainLive 使用: createFrostBackground(img: imageV.image!,view: self.view) 方法: extension ViewController { //创建毛

贡献作者 -【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)
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读