[翻译] MZTimerLabel 用作秒表或者倒计时
MZTimerLabel 用作秒表或者倒计时

https://github.com/mineschan/MZTimerLabel
A handy class for iOS to use UILabel as a countdown timer or stopwatch just like in Apple Clock App.
一个基于UILabel好用的倒计时或者秒表的类。

Purpose(目的)
MZTimerLabel is a UILabel subclass, which is a handy way to use UILabel as a countdown timer or stopwatch just like that in Apple Clock App with just 2 lines of code. MZTimerLabel also provides delegate method for you to define the action when the timer finished.
MZTimerLabel是一个UILabel的子类,两行代码就可以显示秒表效果。它提供代理来帮助你处理倒计时结束后的事件处理。
Auther: MineS Chan
Remark: This is my first iOS plugin project on github, please accept my apologize if any bad coding.
Requirements(要求)
- ARC
- iOS 5.0+
Installations(安装)
Manual
- Download or clone MZTimerLabel, add
MZTimerLabel.handMZTimerLabel.msouce files into your project.将文件夹MZTimerLabel拖入你的工程当中 #import "MZTimerLabel.h"whereever you need it.引入头文件
CocoaPods
(Unformilar with CocoaPods yet? It's a dependency management tool for iOS and Mac, check it out!)
- Add
pod 'MZTimerLabel', '~> 0.4.1'to your podfiles
Easy Example(简单示例)
To use MZTimerLabel as a stopwatch and counter, you need only 2 lines.
使用MZTimerLabel作为秒表或者定时器,你只需两行代码。
MZTimerLabel *stopwatch = [[MZTimerLabel alloc] initWithLabel:aUILabel];
[stopwatch start];
Easy? If you are looking for a timer, things is just similar.
so easy.如果你想使用一个定时器,一样的。
MZTimerLabel *timer = [[MZTimerLabel alloc] initWithLabel:aUILabel andTimerType:MZTimerLabelTypeTimer];
[timer setCountDownTime:60];
[timer start];
Now the timer will start counting from 60 to 0 ;)
现在,时间就会从60到0了。
Custom Appearance(自定义外观)
As MZTimerLabel is a UILabel subclass, you can directly allocate it as a normal UILabel and customizetimeLabel property just like usual.
由于MZTimerLabel是UILabel的子类,你可以直接alloc出来作为一个UILabel然后定制timeLabel属性即可。
MZTimerLabel *redStopwatch = [[MZTimerLabel alloc] init];
redStopwatch.frame = CGRectMake(100,50,100,20);
redStopwatch.timeLabel.font = [UIFont systemFontOfSize:20.0f];
redStopwatch.timeLabel.textColor = [UIColor redColor];
[self.view addSubview:redStopwatch];
[redStopwatch start];
MZTimerLabel uses 00:00:00 (HH:mm:ss) as time format, if you prefer using another format such as including milliseconds.Your can set your time format like below.
MZTimerLabel使用 00:00:00 作为时间格式,如果你想使用毫秒显示。你可以设置成下面的方式。
timerExample4.timeFormat = @"HH:mm:ss SS";
Control the timer(控制定时器)
You can start,pause,reset your timer with your custom control, set your control up and call these methods:
你可以开始,暂停,重设你的定时器:
-(void)start;
-(void)pause;
-(void)reset;
And you control the time at the begining or during runtime with these methods
在定时器开始时或者是启动后修改:
-(void)setCountDownTime:(NSTimeInterval)time;
-(void)setStopWatchTime:(NSTimeInterval)time;
-(void)setCountDownToDate:(NSDate*)date;
-(void)addTimeCountedByTime:(NSTimeInterval)timeToAdd;
Timer Finish Handling(倒计时结束后的控制)
Usually when you need a timer, you need to deal with it after it finished counting. Following are 2 examples showing how to do it using delegate and block methods.
通常你要定时器,是为了结束后能处理一下时间。下面有两个例子来,一个用代理实现,一个用block来实现。
Delegate
First, set the delegate of the timer label.
首先设置代理
timer.delegate = self;
And then implement MZTimerLabelDelegate protocol in your dedicated class
然后实现 MZTimerLabelDelegate 协议
@interface ViewController : UIViewController<MZTimerLabelDelegate>
Finally, implement the delegate method timerLabel:finshedCountDownTimerWithTimeWithTime:
最后,实现代理方法 timerLabel:finshedCountDownTimerWithTimeWithTime:
-(void)timerLabel:(MZTimerLabel*)timerLabel finshedCountDownTimerWithTime:(NSTimeInterval)countTime{
//time is up, what should I do master?
}
Blocks
Block is a very convenient way to handle the callbacks, MZTimerLabel makes your life even easier.
使用block非常便利,MZTimerLabel让你无比轻松。
MZTimerLabel *timer = [[MZTimerLabel alloc] initWithLabel:aUILabel andTimerType:MZTimerLabelTypeTimer];
[timer3 setCountDownTime:60];
[timer startWithEndingBlock:^(NSTimeInterval countTime) {
//oh my god it's awesome!!
}];
[翻译] MZTimerLabel 用作秒表或者倒计时的更多相关文章
- iOS 10 跳转系统设置
苦心人天不负, 为了项目终于把 iOS 10 跳转系统设置的方法给搞定了, 很欣慰. http://www.cnblogs.com/lurenq/p/6189580.html iOS 10 跳转系统设 ...
- C语言运算符与表达式
1 概论 计算机内存中的数据可以通过变量,常量来表示和存储,那么这些数据如何运算? C语言中提供了大量(34种)的运算符可以用来完成数据的算术,赋值,逻辑,关系,条件判断以及自增自减运算和基于二进制的 ...
- Guideline 2.5.1 - Performance - Software Requirements
Guideline - Performance - Software Requirements Your app uses the "prefs:root=" non-public ...
- Mac下截图工具
苹果系统自带截图功能 1.截取全屏:快捷键(Shift+Command+3) ▲直接按“Shift+Command+3“快捷键组合,即可截取电脑全屏,图片自动保存在桌面. 2.截图窗口:快捷键(Shi ...
- NetEQ主要文件简介
accelerate.h,accelerate.cc 加速操作,对语音信号处理以实现快速播放. Accelerate类继承自父类TimeStretch,大多数功能由TimeStretch实现. Ret ...
- mac默认截图、截图代码
苹果系统自带截图功能 1 截取全屏:快捷键(Shift+Command+3) 直接按“Shift+Command+3“快捷键组合,即可截取电脑全屏,图片自动保存在桌面. 2 截图窗口:快捷键(Sh ...
- 带你看看Java的锁(三)-CountDownLatch和CyclicBarrier
带你看看Java中的锁CountDownLatch和CyclicBarrier 前言 基本介绍 使用和区别 核心源码分析 总结 前言 Java JUC包中的文章已经写了好几篇了,首先我花了5篇文章从源 ...
- C面向对象: 升级版本实现:同步逻辑、少量连续失败则增补、多次连续失败则拉长同步周期
// C语言之 面向对象+虚事务的抽象 /*********** 进阶练习: (对虚的事物的抽象) 完善部门职责 ***********************/ #include <stdio ...
- .NET 5的System.Text.Json的JsonDocument类讲解
本文内容来自我写的开源电子书<WoW C#>,现在正在编写中,可以去WOW-Csharp/学习路径总结.md at master · sogeisetsu/WOW-Csharp (gith ...
随机推荐
- PHP array_key_exists() 函数(判断某个数组中是否存在指定的 key)
定义和用法 array_key_exists() 函数判断某个数组中是否存在指定的 key,如果该 key 存在,则返回 true,否则返回 false. 语法 array_key_exists(ke ...
- 一步一步学习IdentityServer4 (2) 开始一个简单的事例
前面将来一些配置,但是很多都不是必要的,先放一些事例需要的简要配置把 既然是IdentityServer4 所里下面的例子我 直接放到 Linux上 测试环境 CentOS 7 +Nginx1.9.3 ...
- Codeforces 429C Guess the Tree(状压DP+贪心)
吐槽:这道题真心坑...做了一整天,我太蒻了... 题意 构造一棵 $ n $ 个节点的树,要求满足以下条件: 每个非叶子节点至少包含2个儿子: 以节点 $ i $ 为根的子树中必须包含 $ c_i ...
- C语言:10个整数排序(别忘了负数)
题目内容: 10个整数排序(别忘了负数) 例如 input 1 0 2 0 3 4 1 9 8 7 output 0 0 1 1 2 3 4 7 8 9 编码: void sort(int *a); ...
- scp和rsync的区别和常用参数
一.scp 命令 1.scp 是 secure copy 的缩写,用于远程的文件的复制. 2.参数: -r: 递归复制整个目录. 3.实例: scp /home/space/music/1.mp3 u ...
- Object-c和Java中的代理
代理模式的核心思想就是一个类想做一件事情(函数),但它不去亲自做(实现),而是通过委托别的类(代理类)来完成. 代理模式的优点: 1.可以实现传值,尤其是当一个对象无法直接获取到另一个对象的指针,又希 ...
- 牛客练习赛1 A - 矩阵
链接:https://www.nowcoder.com/acm/contest/2/A来源:牛客网 题目描述 给出一个n * m的矩阵.让你从中发现一个最大的正方形.使得这样子的正方形在矩阵中出现了至 ...
- Java double 精度
1. 范围 float和double的范围是由指数的位数来决定的. float的指数位有8位,而double的指数位有11位,分布如下: float: 1bit(符号位) 8bits(指数位) ...
- Wireshark数据抓包教程之认识捕获分析数据包
Wireshark数据抓包教程之认识捕获分析数据包 认识Wireshark捕获数据包 当我们对Wireshark主窗口各部分作用了解了,学会捕获数据了,接下来就该去认识这些捕获的数据包了.Wiresh ...
- 部署kettle7.1
系统版本 [root@gaqzj ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 安装JDK1.8 jdk-8u161 ...