【纯代码】Swift - 自定义底部d窗基类(可根据需要自行扩展内容)

【纯代码】Swift - 自定义底部d窗基类(可根据需要自行扩展内容),第1张

概述//d窗视图class PopView : UIView { var selectButtonCallBack:((_ title:String)-> Void)? var contenView:UIView? { didSet{ setUpContent() } }
//d窗视图class PopVIEw : UIVIEw {    var selectbuttonCallBack:((_ Title:String)-> VoID)?        var contenVIEw:UIVIEw?    {        dIDSet{            setUpContent()        }    }        overrIDe init(frame: CGRect) {        super.init(frame: frame)    }        required init?(coder aDecoder: NSCoder) {        fatalError("init(coder:) has not been implemented")    }        func setUpContent(){                if self.contenVIEw != nil {            self.contenVIEw?.frame.origin.y = UIScreen.main.bounds.size.height - 191            self.addSubvIEw(self.contenVIEw!)        }        self.backgroundcolor = newcolorWithAlpha(0,0,0.4)        self.isUserInteractionEnabled = true        self.addGestureRecognizer(UITapGestureRecognizer.init(target: self,action: #selector(dismissVIEw)))        //以下为添加内容,可根据需要删除以下部分        sudokuConstraints()    }        @objc func dismissVIEw(){        UIVIEw.animate(withDuration: 0.3,animations: {            self.Alpha = 0        }) { (true) in            self.removeFromSupervIEw()            self.contenVIEw?.removeFromSupervIEw()        }    }        func showInWindow(){        UIApplication.shared.keyWindow?.addSubvIEw(self)        UIVIEw.animate(withDuration: 0.3,animations: {            self.Alpha = 1.0            self.contenVIEw?.frame.origin.y = UIScreen.main.bounds.size.height - 191        },completion: nil)    }        //MARK: - 布局    func sudokuConstraints() -> VoID {        let TitleArr = ["","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""]                for (index,value) in TitleArr.enumerated() {            let button = createbutton(Title: value)            let margin = (UIScreen.main.bounds.size.wIDth - 8 * 39)/(8 + 1)            let col  = CGfloat(index % Int(8))            let row  = CGfloat(index / Int(8))            let vIEwX = margin +  col * (39 + margin)            let vIEwY = 7 + row * (39 + 7)                        button.frame = CGRect(x: vIEwX,y: vIEwY,wIDth: 39,height: 39)            self.contenVIEw!.addSubvIEw(button)        }    }        func createbutton(Title:String) -> UIbutton {        let button = UIbutton()        button.setTitle(Title,for: .normal)        button.setTitlecolor(newcolor(0,0),for: .normal)        button.backgroundcolor = .white        button.layer.masksToBounds = true        button.layer.cornerRadius = 5.0                button.addTarget(self,action: #selector(buttonClickAction(button:)),for: .touchUpInsIDe)        return button    }        @objc func buttonClickAction(button:UIbutton) -> VoID {        if self.selectbuttonCallBack != nil {            self.selectbuttonCallBack!(button.TitleLabel?.text ?? "")        }    }}

使用:

let popvIEw = PopVIEw.init(frame:UIScreen.main.bounds)        popvIEw.contenVIEw = UIVIEw.init(frame: CGRect.init(x: 0,y: UIScreen.main.bounds.size.height - 191,wIDth: UIScreen.main.bounds.size.wIDth,height:191 ))popvIEw.contenVIEw?.backgroundcolor = newcolor(206,206,206)popvIEw.selectbuttonCallBack = {    (Title:String) -> VoID in    self.righAbbreviationbutton.setTitle(Title,for: .normal)    popvIEw.dismissVIEw()}popvIEw.showInWindow()

效果图:

总结

以上是内存溢出为你收集整理的【纯代码】Swift - 自定义底部d窗基类(可根据需要自行扩展内容)全部内容,希望文章能够帮你解决【纯代码】Swift - 自定义底部d窗基类(可根据需要自行扩展内容)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1017434.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存