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 ,小编也想给大家多分享点有用的干货,让大家边学边用.好了,闲话不多说,今天要给各位看官们 ...
随机推荐
- C#高级编程笔记 2016年10月8日运算符和类型强制转换
1.checked和unchecked 运算符 C#提供了checked 和uncheckde 运算符.如果把一个代码块标记为checked, CLR就会执行溢出检查,如果发生溢出,就抛出overfl ...
- hmm
http://www.cnblogs.com/mindpuzzle/p/3653043.html http://en.wikipedia.org/wiki/Viterbi_algorithm http ...
- 自己总结SVN必知点
1.只有添加或删除文件,才与xcodeproj文件有关 2.本地新建文件,为未知文件,符号为问号?,添加文件先add为A文件后,再commit 3.删除文件为叹号,右键删除为D,删除本 ...
- Servlet 生命周期与web容器的关系
servlet生命周期由web容器(如tomcat)管理,初始化一次,直到web容器关闭才会被销毁.1.servlet是单例多线程,每个请求过来容器都会启用一个新线程 2.servlet在容器中保持单 ...
- byte数组和File,InputStream互转
1.将File.FileInputStream 转换为byte数组: File file = new File("file.txt"); InputStream input = n ...
- php中"::"双冒号有什么作用
PHP代码 lazycms::$sysname 第一次见到这种表现方式,请问是双冒号什么意思 答:直接属类的方法或属性.也就是static 静态方法或属性的使用.域运算符,一般用于在B类对象中使用A类 ...
- OpenGL 多视图与截屏
最近看红宝书学习 OpenGL 一段时间了,写了简单的 demo 程序温习一下知识. 主要是 使用 glScissor 多视图显示画面和使用 glReadPixels 给画面截屏,使用显示列表(dis ...
- Power BI for Office 365(三)Power Pivot
在Power Pivot中可以从各种数据源中根据你的需求来创建数据模型,并且可以根据需要随时刷新这些数据.在上一篇中,Anna已经准备好了加载到Power Pivot中的数据.Power Pivot就 ...
- JDK常用工具集——jps
该命令的作用是罗列出目标系统(target system)中所有具有访问权限到的Java进程. 一.命令简介: jps [option] [hostid] 二.参数说明: option ...
- android tab选项卡的使用
项目做完了,写写博客,在项目中遇到的一些问题,或者是自己觉得很不错的东西.这一篇主要是想和大家分享一下我在项目中封装的一个东西,就是tab选项卡.先看看效果图: 我在网上看了很多有关选项卡的demo, ...