import UIKit

class FourVC: UIViewController {

    var label:UILabel = UILabel()
var index : Int =
var timer:Timer = Timer()
override func viewDidLoad() {
super.viewDidLoad() label = UILabel.init()
label.frame = CGRect.init(x:,y:,width: ,height:)
label.text = "计时器"
label.textColor = UIColor.black
self.view.addSubview(label) timer = Timer.scheduledTimer(timeInterval: , target: self, selector: #selector(createTimer), userInfo: nil, repeats: true)
RunLoop.current.add(timer, forMode: RunLoopMode.commonModes)
timer.fireDate = NSDate.distantFuture let endTimeBtn : UIButton = UIButton()
endTimeBtn.frame = CGRect.init(x:,y:,width: ,height:)
endTimeBtn.backgroundColor = UIColor.cyan
endTimeBtn.setTitle("停止计时", for: UIControlState.normal)
endTimeBtn.titleColor(for: UIControlState.normal)
endTimeBtn.setTitleColor(UIColor.black, for: UIControlState.normal)
endTimeBtn.addTarget(self, action: #selector(pressBtn1), for: UIControlEvents.touchUpInside)
self.view.addSubview(endTimeBtn) let startTimeBtn : UIButton = UIButton()
startTimeBtn.frame = CGRect.init(x:,y:,width: ,height:)
startTimeBtn.backgroundColor = UIColor.cyan
startTimeBtn.setTitle("开始计时", for: UIControlState.normal)
startTimeBtn.titleColor(for: UIControlState.normal)
startTimeBtn.setTitleColor(UIColor.black, for: UIControlState.normal)
startTimeBtn.addTarget(self, action: #selector(pressBtn), for: UIControlEvents.touchUpInside)
self.view.addSubview(startTimeBtn) } func pressBtn(){ //开始计时,很远的过去
timer.fireDate = NSDate.distantPast } func pressBtn1(){
//关闭计时,很远的将来
timer.fireDate = NSDate.distantFuture }
func createTimer(){ index +=
label.text = "\(index)" if index == {
//关闭计时器
timer.fireDate = NSDate.distantFuture
label.text = "倒计时停止\(index)"
} } override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

swfit-计时器的更多相关文章

  1. android 两种实现计时器时分秒的实现,把时间放在你的手中~

    可能我们在开发中会时常用到计时器这玩意儿,比如在录像的时候,我们可能需要在右上角显示一个计时器.这个东西其实实现起来非常简单. 只需要用一个控件Chronometer,是的,就这么简单,我都不好意思讲 ...

  2. TCP四种计时器

    TCP共使用以下四种计时器,即重传计时器.坚持计时器.保活计时器和时间等待计时器 .这几个计时器的主要特点如下:      1.重传计时器      当TCP发送报文段时,就创建该特定报文段的重传计时 ...

  3. C# - 计时器Timer

    System.Timers.Timer 服务器计时器,允许指定在应用程序中引发事件的重复时间间隔. using System.Timers: // 在应用程序中生成定期事件 public class ...

  4. JavaScript学习笔记5 之 计时器 & scroll、offset、client系列属性 & 图片无缝滚动

    一.计时器 setInterval ( 函数/名称 , 毫秒数 )表示每经过一定的毫秒后,执行一次相应的函数(重复) setTimeout ( 函数/名称 , 毫秒数 ) 表示经过一定的毫秒后,只执行 ...

  5. VBA中使用计时器的两种方法

    '================================ ' VBA采用Application.OnTime实现计时器 ' ' http://www.cnhup.com '========= ...

  6. js 短信验证码 计时器

    $(function(){ getMsg(); //页面加载完成之后执行 }) function getMsg(){ //注册按钮的点击事件 $("#smsBtn").on(&qu ...

  7. 【效率】专为Win7系统设计的极简番茄计时器 - MiniPomodoro (附源码)

    时光飞逝,一转眼坚持使用番茄工作法已经快3年了!能坚持这么长时间,主要还是得益于它的简单.但是令人纠结的是,这么长时间以来,换了7款不同的番茄计时器,仍然没有找到非常满意的: ■ 机械的噪音太大,会妨 ...

  8. 计时器StopWatch示例

    计时器 StopWatch stwatch = new StopWatch(getClass().getSimpleName()); try{ stwatch.start(joinPoint.getS ...

  9. SharePoint 2013 图文开发系列之计时器任务

    SharePoint的计时器任务,又称TimerJob,由服务里的Timer服务执行,在管理中心管理,是一个类似于Windows任务计划的功能,方便定时执行一些需要的功能,以免影响服务器性能. 在Sh ...

  10. DIY一个高大上带提醒的计时器,简单实用,你还在等什么

    小编心语:锵锵锵!小编我又来了!昨天发了一篇比较实用的<Python聊天室>,鉴于反响还不错,SO ,小编也想给大家多分享点有用的干货,让大家边学边用.好了,闲话不多说,今天要给各位看官们 ...

随机推荐

  1. 未备案域名打开国内服务器上的网站(绑定国外空间并判断url后跳转引用)

    场景:由于域名没备案不能绑定国内服务器,通过先绑定国外空间,在空间着陆页判断当前url,打开不同的页面.页面上通过iframe引用国内服务器上的目标网站. 实现:未备案域名打开国内服务器上的网站. 国 ...

  2. [转]Ubantu vmware tools 安装

    https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&external ...

  3. javascript删除数组某个元素

    1.首先可以给js的数组对象定义一个函数,用于查找指定的元素在数组中的位置,即索引 Array.prototype.indexOf = function(val) { for (var i = 0; ...

  4. iOS On-Demand Resources简单理解

    ios9引入了一个新功能,On-Demand Resources,它是app thinning 的一部分.这个机能简单的说,就是在下载app的时候,app中包含的不重要资源不下载,等到需要时,在由系统 ...

  5. HTML 简单的介绍

    Q: 什么是HTML? A: HTML 是一种超文本标记语言. 所谓的超文本是指指页面内可以包含图片,链接,甚至音乐.程序等非文字元素.超文本标记语言的结构包括"头"部分(英语:H ...

  6. 可以改变this指向的方法

    this一般指向的是当前被调用者,但也可以通过其它方式来改变它的指向,下面将介绍三种方式: 1.call用作继承时: function Parent(age){ this.name=['mike',' ...

  7. Mac Pro 16G 安装MyEclipse提示虚拟内存(为0)不够

    百度一下很多人都说开多一点程序,让程序占满内存,使其虚拟内存使用就能通过这一步骤,但这里有个更好一点的方案 通过执行: memory_pressure -l critical 用系统内存压力测试进程占 ...

  8. html+css做的丝带标签

    先上效果: HTML: <div class="tag"> <div class="tag-box"> <div class=&q ...

  9. Struts2漏洞利用实例

    Struts2漏洞利用实例 如果存在struts2漏洞的站,administrator权限,但是无法加管理组,内网,shell访问500. 1.struts2 漏洞原理:struts2是一个框架,他在 ...

  10. http返回码301、302、307、305含义和区别

    301永久重定向,302暂时移动,seo对301和302的处理不一样: 301和302会出现数据丢失问题,重定向后请求数据丢失: 307临时重定向,数据不会丢失: