MZTimerLabel
============
<img align="center" src="https://raw.github.com/mineschan/MZTimerLabel/master/MZTimerLabel_Demo.png" alt="ScreenShot" width="300">
<img align="center" src="https://raw.github.com/mineschan/MZTimerLabel/master/MZTimerLabel_Demo2.png" alt="ScreenShot2" width="300">
###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.
Author: [MineS Chan](https://github.com/mineschan/)
_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
1. Download or clone MZTimerLabel, add `MZTimerLabel.h` and `MZTimerLabel.m` source files into your project.
2. `#import "MZTimerLabel.h"` whereever you need it.
####CocoaPods
(Unfamiliar with [CocoaPods](http://cocoapods.org/) yet? It's a dependency management tool for iOS and Mac, check it out!)
1. Add `pod 'MZTimerLabel', '~> 0.5'` to your podfiles
###Easy Example
To use MZTimerLabel as a stopwatch and counter, you need only __2 lines__.
```objective-c
MZTimerLabel *stopwatch = [[MZTimerLabel alloc] initWithLabel:aUILabel];
[stopwatch start];
```
Easy? If you are looking for a timer, things is just similar.
```objective-c
MZTimerLabel *timer = [[MZTimerLabel alloc] initWithLabel:aUILabel andTimerType:MZTimerLabelTypeTimer];
[timer setCountDownTime:60];
[timer start];
```
Now the timer will start counting from 60 to 0 ;)
###Custom Appearance
As MZTimerLabel is a UILabel subclass, you can directly allocate it as a normal UILabel and customize `timeLabel` property just like usual.
```objective-c
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.
`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;
```
#### Getter and Setters
You may control the time value and behaviours at the begining or during runtime with these properties and methods
```
@property (assign) BOOL shouldCountBeyondHHLimit; //see example #12
@property (assign) BOOL resetTimerAfterFinish; //see example #7
-(void)setCountDownTime:(NSTimeInterval)time;
-(void)setStopWatchTime:(NSTimeInterval)time;
-(void)setCountDownToDate:(NSDate*)date;
-(void)addTimeCountedByTime:(NSTimeInterval)timeToAdd; //see example #10, #11
```
And if you want to have information of the timer, here is how.
```
@property (assign,readonly) BOOL counting; //see example #4-7
- (NSTimeInterval)getTimeCounted; //see example #3
- (NSTimeInterval)getTimeRemaining; //see example #3
```
###Timer Finish Handling
Usually when you need a timer, you need to deal with it after it finished. Following are 2 examples showing how to do it using `delegate` and `block` methods.
####Delegate
First, set the delegate of the timer label.
`timer.delegate = self;`
And then implement `MZTimerLabelDelegate` protocol in your dedicated class
`@interface ViewController : UIViewController<MZTimerLabelDelegate>`
Finally, implement the delegate method `timerLabel:finshedCountDownTimerWithTimeWithTime:`
```objective-c
-(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.
```objective-c
MZTimerLabel *timer = [[MZTimerLabel alloc] initWithLabel:aUILabel andTimerType:MZTimerLabelTypeTimer];
[timer3 setCountDownTime:60];
[timer startWithEndingBlock:^(NSTimeInterval countTime) {
//oh my gosh, it's awesome!!
}];
```
Or set it seperately
```
[timer3 setCountDownTime:60];
timer.endedBlock = ^(NSTimeInterval countTime) {
//oh my gosh, it's awesome!!
};
[timer start];
```
###More Examples
Please check the demo project I provided, with well explained example code inside.
###License
This code is distributed under the terms and conditions of the [MIT license](LICENSE).
### What's coming up next?
1. ~~Submit to CocaPods~~
2. ~~Better performance.~~
3. __Your suggestions!:D__
没有合适的资源?快使用搜索试试~ 我知道了~
基于label的倒计时框架
共30个文件
m:4个
plist:3个
h:3个
需积分: 10 8 下载量 101 浏览量
2015-08-31
09:24:55
上传
评论
收藏 226KB ZIP 举报
温馨提示
这是一个很简单的也很好用的第三方框架,只要几行代码就能搞定 倒计时等等时间的控件
资源推荐
资源详情
资源评论
收起资源包目录
封装倒计时框架.zip (30个子文件)
封装倒计时框架
MZTimerLabel_Demo.png 69KB
LICENSE 1KB
MZTimerLabel
MZTimerLabel.h 4KB
MZTimerLabel.m 11KB
MZTimerLabel.podspec 1KB
README.md 5KB
MZTimerLabel_Demo2.png 93KB
.gitignore 237B
MZTimerLabelDemo
MZTimerLabelDemo.xcodeproj
project.xcworkspace
contents.xcworkspacedata 161B
xcuserdata
donelaccount.xcuserdatad
UserInterfaceState.xcuserstate 13KB
baoxiuyizhantong.xcuserdatad
UserInterfaceState.xcuserstate 16KB
xcuserdata
donelaccount.xcuserdatad
xcschemes
xcschememanagement.plist 488B
MZTimerLabelDemo.xcscheme 3KB
baoxiuyizhantong.xcuserdatad
xcschemes
xcschememanagement.plist 488B
MZTimerLabelDemo.xcscheme 3KB
project.pbxproj 14KB
.DS_Store 6KB
MZTimerLabelDemo
en.lproj
Main.strings 236B
InfoPlist.strings 45B
main.m 496B
MZTLViewController.m 12KB
MZTimerLabelDemo-Prefix.pch 344B
MZTimerLabelDemo-Info.plist 1KB
MZTLAppDelegate.m 594B
DemoView.xib 37KB
Images.xcassets
LaunchImage.launchimage
Contents.json 442B
AppIcon.appiconset
Contents.json 333B
MainView.xib 3KB
MZTLViewController.h 3KB
MZTLAppDelegate.h 523B
共 30 条
- 1
资源评论
土鳖不土
- 粉丝: 31
- 资源: 39
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于串口通信的光通信上位机,包括运动控制和通信协议
- 串口与以太网文件传送协议(或自定义控制协议)
- Qt开发windows系统安装教程与代码实例.txt
- QT6实现的附带文件传输协议的串口终端
- 一个串口通讯类和调用Demo 通过设置串口、设置串口自定义协议,可方便对串口发送数据与接收数据
- 华为OD模拟题及参考答案.仅供学习和模拟考试使用
- stm32f103c8t6基于modbus协议和使用串口读取温湿度
- 英雄联盟LOL金克斯4K电脑壁纸
- Microbrain道闸产品上位机,以MahApps库为基础搭建界面,集成了串口(UART)、CAN、WIFI通信,十六进制协议
- Android串口通讯, 支持发送数据回调, 支持并发处理, 自定义协议, CRC校验, 自动粘包, 自动去除冗余的干扰数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功