//弹窗视图
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 -
self.addSubview(self.contenView!)
}
self.backgroundColor = newColorWithAlpha(, , , 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 =
}) { (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 -
}, 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 - * )/( + )
let col = CGFloat(index % Int())
let row = CGFloat(index / Int())
let viewX = margin + col * ( + margin)
let viewY = + row * ( + ) button.frame = CGRect(x: viewX, y: viewY, width: , height: )
self.contenView!.addSubview(button)
}
} func createButton(title:String) -> UIButton {
let button = UIButton()
button.setTitle(title, for: .normal)
button.setTitleColor(newColor(, , ), 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: , y: UIScreen.main.bounds.size.height - , width: UIScreen.main.bounds.size.width, height: ))
popview.contenView?.backgroundColor = newColor(, , )
popview.selectButtonCallBack = {
(title:String) -> Void in
self.righAbbreviationButton.setTitle(title, for: .normal)
popview.dismissView()
}
popview.showInWindow()

效果图:

【纯代码】Swift - 自定义底部弹窗基类(可根据需要自行扩展内容)的更多相关文章

  1. 编写高质量代码改善C#程序的157个建议——建议23:避免将List<T>作为自定义集合类的基类

    建议23:避免将List<T>作为自定义集合类的基类 如果要实现一个自定义的集合类,不应该以一个FCL集合类为基类,反而应扩展相应的泛型接口.FCL结合类应该以组合的形式包含至自定义的集合 ...

  2. 【转】C++ 虚函数&纯虚函数&抽象类&接口&虚基类

    1. 动态多态 在面向对象语言中,接口的多种不同实现方式即为多态.多态是指,用父类的指针指向子类的实例(对象),然后通过父类的指针调用实际子类的成员函数. 多态性就是允许将子类类型的指针赋值给父类类型 ...

  3. C++ 虚函数&纯虚函数&抽象类&接口&虚基类(转)

    http://www.cnblogs.com/fly1988happy/archive/2012/09/25/2701237.html 1. 多态 在面向对象语言中,接口的多种不同实现方式即为多态.多 ...

  4. 关于TagHelper的那些事情——如何自定义TagHelper(TagHelper基类)

    写在开头 前面介绍了TagHelper的基本概念和内嵌的TagHelpers,想必大家对TagHelper都有一定的了解.TagHelper看上去有点像WebControl,但它不同于WebContr ...

  5. qt 5 小练习 纯代码制作自定义按钮

    大家都知道QT设计师中直接拖动的按钮是长方形带有圆角的图案,那我们如何来设置自定义按钮呢 要设计一个按钮,我们必须要知道按钮有什么属性,首先,按钮必须有一个位置 第二,按钮必须有一个名称.还有当我们点 ...

  6. 25.自定义mixin和基类

    很多时候业务需求并不是几个简单的mixin就可以满足,需要我们自定义mixin # get_object源码中字段查询源代码 filter_kwargs = {self.lookup_field: s ...

  7. C++ - 虚基类、虚函数与纯虚函数

    虚基类       在说明其作用前先看一段代码 class A{public:    int iValue;}; class B:public A{public:    void bPrintf(){ ...

  8. ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局

    本文转自 :http://www.cnblogs.com/wendingding/p/3761730.html ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布 ...

  9. 编写高质量代码改善C#程序的157个建议[勿选List<T>做基类、迭代器是只读的、慎用集合可写属性]

    前言 本文已更新至http://www.cnblogs.com/aehyok/p/3624579.html .本文主要学习记录以下内容: 建议23.避免将List<T>作为自定义集合类的基 ...

随机推荐

  1. C# DataTable和DataRelation

    form2.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.D ...

  2. 20165330 2017-2018-2 《Java程序设计》第4周学习总结

    课本知识总结 第五章 子类与继承 子类:在类的声明中,通过使用关键字extends来定义一个类的子类. class 子类名 extends 父类名 { ... } 继承:子类继承父类的成员变量作为自己 ...

  3. because of an existing model object of the same name

    背景: 视图解析器(我们用的是velocity) 报错: because of an existing model object of the same name 按照网上给的原因 : 设置了属性ex ...

  4. 【Python Programe】使用Python发送语音验证

    使用Python向手机发送语音验证码,需要工具有: virtualenv 创建独立运行环境 Twilio 帐号去调用相应的API Twilio 的python库,5.7.0版本 1.使用 virtua ...

  5. C# ArcEngine 实现点击要素高亮并弹出其属性

    本文是模仿ArcMap里面的Identify(识别)功能,通过点击要素,使其高亮显示并弹出其属性表!本文只做了点击查询! 本文所用的环境为VS2010,AecEngine基于C#语言,界面是用Dev做 ...

  6. python console

    print(sys.stdout.encoding, locale.getpreferredencoding ()) windows console : chcp 65001; 在设置了这个环境变量时 ...

  7. python基础-第十一篇-11.2DOM为文档操作

    文档对象模型(DOM)是一种用于HTML和XML文档的编程接口 节点类型 12种节点类型都有NodeType属性来表明节点类型 节点关系 <div id="t"> &l ...

  8. Flask的配置与路由

    配置管理 flask中的配置文件是一个flask.config.Config对象(继承字典),默认配置为:    {        'DEBUG':                    get_de ...

  9. pycharm自定义代码片段

    pycharm自定义代码片段 目录 (一)通用阶段 0 .新建.py文件模板:2 0 .pycharm中添加自定义代码片段:一图全知道:3 1 .定义类:classin              描述 ...

  10. java-mybaits-00502-案例-映射分析-一对一、一对多、多对多

    1.一对一查询[类属性即可,association ] 案例:查询所有订单信息,关联查询下单用户信息.   注意:因为一个订单信息只会是一个人下的订单,所以从查询订单信息出发关联查询用户信息为一对一查 ...