//弹窗视图
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. CSS 垂直外边距合并:规范、延伸、原理、解决办法

    <CSS 权威指南>第七章基本视觉格式化.p192,提到了 垂直外边距合并 的情况,解释总体算清晰,但是感觉不全且没有归纳成一条一条的,参考 CSS框模型中外边距(margin)折叠图文详 ...

  2. excel提取汉字拼音首字母

    本文转载:http://jingyan.baidu.com/article/63acb44adca44461fcc17e85.html 利用Excel表格中的宏,轻松提取首字母 方法/步骤 1.启动E ...

  3. AngularJS 解决 SEO 问题

    由于 AngularJS 返回的是HTML模板,实际的内容需要执行JS以后才会填充进去,导致百度抓取蜘蛛抓不到,因此产生了 AngularJS 的 SEO 问题.经过几天的研究试验,我们的解决方案是这 ...

  4. [linux基础学习]默认的目录介绍

    以下用一个表格来罗列linux默认的目录或文件及其用途: 目录/文件 用途 来源 / /处于Linux文件系统树形结构的最顶端,它是Linux文件系统的入口,所有的目录.文件.设备都在/之下. - / ...

  5. 2017 Multi-University Training Contest - Team 1—HDU6033&&HDU6034

    HDU6033  Add More Zero 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6033 题目意思:给一个m,求一个数k使得10^k最接近2 ...

  6. Elastic Load Balancing with Sticky Sessions

    Elastic Load Balancing with Sticky Sessions — Shlomo Swidler https://shlomoswidler.com/2010/04/elast ...

  7. MICRO-SERVICE

    这个缩放立方体 (scale cube) 演示了各种可用的缩放选项: 缩放立方体 X 轴缩放 分担了应用程序的多个副本之间的工作负载,通常会使用一个负载平衡器或一个集群管理器. Y 轴缩放 将应用程序 ...

  8. Spark 源码分析 -- task实际执行过程

    Spark源码分析 – SparkContext 中的例子, 只分析到sc.runJob 那么最终是怎么执行的? 通过DAGScheduler切分成Stage, 封装成taskset, 提交给Task ...

  9. Ignatius and the Princess IV---hdu1029(动态规划或者sort)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 就是给你n(n是奇数)个数找出个数大于(n+1)/ 2 的那个数: n的取值范围是 n(1< ...

  10. GlusterFS部署

    一.GlusterFS简介 PB级容量.高可用.读写性能.基于文件系统级别共享.分布式.无metadata(元数据)的存储方式. GlusterFS(GNU ClusterFile System)是一 ...