• swift高斯模糊的自定义view


     var bgImage = UIImageView()

        var backButton = UIButton()

        var titleLabel = UILabel()

        let screen_h = UIScreen.main.bounds.height

        let screen_w = UIScreen.main.bounds.width

        

        override init(frame: CGRect) {

            super.init(frame: frame)

            initUI()

        }

        

        

        required init?(coder aDecoder: NSCoder) {

            fatalError("init(coder:) has not been implemented")

        }

        

        func initUI() {

    //        bgImage.frame=CGRect(x:0,y:0,screen_w,height:64)

    //        bgImage.backgroundColor = UIColor(patternImage: UIImage(named:"navbar_bg")!)

    //        self.addSubview(bgImage)

            

            //首先创建一个模糊效果

            let blurEffect = UIBlurEffect(style: .dark)

            //接着创建一个承载模糊效果的视图

            let blurView = UIVisualEffectView(effect: blurEffect)

            //设置模糊视图的大小(全屏)

            blurView.frame.size = CGSize( screen_w, height: 64)

            //添加模糊视图到页面view上(模糊视图下方都会有模糊效果)

            blurView.alpha=0.7

            self.addSubview(blurView)

            

            backButton = UIButton(type: .custom)

            backButton.frame = CGRect(x:0 , y:20, 60, height:44)

            backButton.backgroundColor = UIColor.clear

            backButton.setImage(UIImage(named:"btn_Return"), for: .normal)

            self.addSubview(backButton)

            

            titleLabel.frame=CGRect(x:screen_w/2-100,y:20+44/2-8,200,height:18)

            titleLabel.text="Old glass"

            titleLabel.textColor=UIColor.white

            titleLabel.textAlignment = .center

            titleLabel.font = UIFont(name: "Arial", size: 16.0)

            self.addSubview(titleLabel)

        }

  • 相关阅读:
    Hackerrank--Savita And Friends(最小直径生成树MDST)
    Hackerrank--Kundu and Tree
    Hackerrank--String Function Calculation(后缀数组)
    Hackerrank--Ashton and String(后缀数组)
    Foundation 学习
    JS 严格模式
    判断移动设备横竖屏
    Nodejs解析HTML网页模块 jsdom
    百度Map调用
    Jade 报错
  • 原文地址:https://www.cnblogs.com/-ios/p/7801073.html
Copyright © 2020-2023  润新知