swfit-计时器
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-计时器的更多相关文章
- android 两种实现计时器时分秒的实现,把时间放在你的手中~
可能我们在开发中会时常用到计时器这玩意儿,比如在录像的时候,我们可能需要在右上角显示一个计时器.这个东西其实实现起来非常简单. 只需要用一个控件Chronometer,是的,就这么简单,我都不好意思讲 ...
- TCP四种计时器
TCP共使用以下四种计时器,即重传计时器.坚持计时器.保活计时器和时间等待计时器 .这几个计时器的主要特点如下: 1.重传计时器 当TCP发送报文段时,就创建该特定报文段的重传计时 ...
- C# - 计时器Timer
System.Timers.Timer 服务器计时器,允许指定在应用程序中引发事件的重复时间间隔. using System.Timers: // 在应用程序中生成定期事件 public class ...
- JavaScript学习笔记5 之 计时器 & scroll、offset、client系列属性 & 图片无缝滚动
一.计时器 setInterval ( 函数/名称 , 毫秒数 )表示每经过一定的毫秒后,执行一次相应的函数(重复) setTimeout ( 函数/名称 , 毫秒数 ) 表示经过一定的毫秒后,只执行 ...
- VBA中使用计时器的两种方法
'================================ ' VBA采用Application.OnTime实现计时器 ' ' http://www.cnhup.com '========= ...
- js 短信验证码 计时器
$(function(){ getMsg(); //页面加载完成之后执行 }) function getMsg(){ //注册按钮的点击事件 $("#smsBtn").on(&qu ...
- 【效率】专为Win7系统设计的极简番茄计时器 - MiniPomodoro (附源码)
时光飞逝,一转眼坚持使用番茄工作法已经快3年了!能坚持这么长时间,主要还是得益于它的简单.但是令人纠结的是,这么长时间以来,换了7款不同的番茄计时器,仍然没有找到非常满意的: ■ 机械的噪音太大,会妨 ...
- 计时器StopWatch示例
计时器 StopWatch stwatch = new StopWatch(getClass().getSimpleName()); try{ stwatch.start(joinPoint.getS ...
- SharePoint 2013 图文开发系列之计时器任务
SharePoint的计时器任务,又称TimerJob,由服务里的Timer服务执行,在管理中心管理,是一个类似于Windows任务计划的功能,方便定时执行一些需要的功能,以免影响服务器性能. 在Sh ...
- DIY一个高大上带提醒的计时器,简单实用,你还在等什么
小编心语:锵锵锵!小编我又来了!昨天发了一篇比较实用的<Python聊天室>,鉴于反响还不错,SO ,小编也想给大家多分享点有用的干货,让大家边学边用.好了,闲话不多说,今天要给各位看官们 ...
随机推荐
- Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)
题目链接:http://codeforces.com/contest/522/problem/D 题目大意: 给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...
- MongoDB C Driver使用教程
MongoDB C Driver使用教程 转载请注明出处http://www.cnblogs.com/oloroso/ 本指南提供简介 MongoDB C 驱动程序. 在 C API 的详细信息,请参 ...
- CH Round #56 - 国庆节欢乐赛解题报告
最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...
- tomcate端口设定和服务器虚拟目录设定
设定端口和 虚拟目录 在server.xml <?xml version='1.0' encoding='utf-8'?> <!-- Licensed to the Apa ...
- C++ 判断字符串是否全是数字
在实际的工作中,需要提取程序中的字符串信息,但是程序中经常将一些数字当做字符串来进行处理,例如表盘的刻度信息,这时候就需要判断字符串是否全为数字,来进行真正意义上的字符串提取.下面介绍了判断字符串是否 ...
- session超时时间设置方法
session超时时间设置方法 由于session值之前没有设置,以至于刚登录的网站,不到一分钟就超时了,总结了一下,原来是session过期的原因,以下是设置session时间的3个方法: 1. 在 ...
- 基于Netty4的HttpServer和HttpClient的简单实现
Netty的主页:http://netty.io/index.html 使用的Netty的版本:netty-4.0.23.Final.tar.bz2 ‐ 15-Aug-2014 (Stable, Re ...
- POJ2104 K-th Number(归并树)
平方分割一直TLE,最后用归并树处理过了,使用STL会比较慢. #include<cstdio> #include<iostream> #include<cstdlib& ...
- SQL基础之基本操作
1.UNION操作符 union操作符用来合并两个或多个select语句的结果,要注意union内部的每个select语句必须拥有相同数量的列,而且列也必须拥有相似的数据类型和相同的列顺序.下面是我的 ...
- OSI七层模型及TCP/IP四层模型
1) OSI七层模型及TCP/IP四层模型 OSI七层模型:是国际标准化组织(ISO)制定的一个用于计算机或通信系统间互联的标准体系.它是一个七层的.抽象的模型,不仅包括一系列抽象的术语或概念,也包 ...