iOS UIButton倒计时方法——MZTimerLabel
2014-10-27 00:00
656 查看
先前发了一个关于dispatch方法来进行倒计时的,不过相对来说MZTimerLabel更好用一点。现在说一下MZTimerLabel的使用方法。
首先,因为这是一个库函数,所以必须要有这个库了,xcode不带这个库,使用前请先下载该库。
MZTimerLabel
下载下来之后先把两个头文件加载到工程里面
然后在需要用倒计时的函数里导入MZTimerLabel的库,并且设置代理,因为后面如果倒计时结束后要自动调用事件的话会调用MZTimerLabel的代理方法
把要倒计时的UIButton和storyboard的控件相连
现在来上一下倒计时函数的代码
倒计时结束后自动调用代理方法
觉得还不错,可以调整的方法比较多,拓展性比较强。
首先,因为这是一个库函数,所以必须要有这个库了,xcode不带这个库,使用前请先下载该库。
MZTimerLabel
下载下来之后先把两个头文件加载到工程里面
然后在需要用倒计时的函数里导入MZTimerLabel的库,并且设置代理,因为后面如果倒计时结束后要自动调用事件的话会调用MZTimerLabel的代理方法
把要倒计时的UIButton和storyboard的控件相连
现在来上一下倒计时函数的代码
@interface RegisterViewController ()<MZTimerLabelDelegate> { UILabel *timer_show;//倒计时label }
- (void)timeCount{//倒计时函数 [_dynamicCode_btn setTitle:nil forState:UIControlStateNormal];//把按钮原先的名字消掉 timer_show = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 85, 30)];//UILabel设置成和UIButton一样的尺寸和位置 [_dynamicCode_btn addSubview:timer_show];//把timer_show添加到_dynamicCode_btn按钮上 MZTimerLabel *timer_cutDown = [[MZTimerLabel alloc] initWithLabel:timer_show andTimerType:MZTimerLabelTypeTimer];//创建MZTimerLabel类的对象timer_cutDown [timer_cutDown setCountDownTime:60];//倒计时时间60s timer_cutDown.timeFormat = @"倒计时 ss";//倒计时格式,也可以是@"HH:mm:ss SS",时,分,秒,毫秒;想用哪个就写哪个 timer_cutDown.timeLabel.textColor = [UIColor whiteColor];//倒计时字体颜色 timer_cutDown.timeLabel.font = [UIFont systemFontOfSize:13.0];//倒计时字体大小 timer_cutDown.timeLabel.textAlignment = NSTextAlignmentCenter;//剧中 timer_cutDown.delegate = self;//设置代理,以便后面倒计时结束时调用代理 _dynamicCode_btn.userInteractionEnabled = NO;//按钮禁止点击 [timer_cutDown start];//开始计时 }
倒计时结束后自动调用代理方法
//倒计时结束后的代理方法 - (void)timerLabel:(MZTimerLabel *)timerLabel finshedCountDownTimerWithTime:(NSTimeInterval)countTime{ [_dynamicCode_btn setTitle:@"发送验证码" forState:UIControlStateNormal];//倒计时结束后按钮名称改为"发送验证码" [timer_show removeFromSuperview];//移除倒计时模块 _dynamicCode_btn.userInteractionEnabled = YES;//按钮可以点击 }
觉得还不错,可以调整的方法比较多,拓展性比较强。
相关文章推荐
- MZTimerLabel 用作秒表或者倒计时
- MZTimerLabel 用作秒表或者倒计时
- [翻译] MZTimerLabel 用作秒表或者倒计时
- ios开发之倒计时实现的两种方法
- ios开发之倒计时实现的两种方法
- IOS UIButton 常用方法介绍
- IOS基本控件常用属性及方法(四)---UIButton
- ios开发之倒计时实现的两种方法
- IOS 笔记 - 利用UIImage的stretchableImageWithLeftCapWidth方法给UIButton设置背景
- ios开发之倒计时实现的两种方法
- iOS 倒计时方法——dispatch
- 【iOS开发-46】利用UIButton和UIImageView的区别分辨哪些控件有addTarget监听事件这个方法
- iOS UIButton 给某个角设置为圆角的方法
- ios开发之倒计时实现的两种方法
- iOS UIButton 等方法 按钮
- iOS 开发之 为UIButton添加类别方法加载网络图片
- IOS--UIButton的常用属性和方法
- 【iOS】UIButton 传递多个参数的方法 -----使用关联函数
- IOS--UIButton的使用方法
- iOS开发利用UIButton和UIImageView的区别分辨哪些控件有addTarget监听事件这个方法