iOS倒計(jì)時(shí)的實(shí)現(xiàn)方法
本文實(shí)例為大家分享了iOS倒計(jì)時(shí)的具體實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下
效果
用法
1.導(dǎo)入Timer.h/.m文件
2.所需界面導(dǎo)入頭文件 #import “Timer.h”,其他設(shè)置參考源碼
源碼
github:https://github.com/makingitbest/CountDownTimer
細(xì)節(jié)
#import "ViewController.h" #import "Timer.h" @interface ViewController ()<TimerDelegate> @property (nonatomic, strong) UIButton *button; @property (nonatomic, strong) Timer *timer; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // 倒計(jì)時(shí)界面 self.timer = [[Timer alloc] initWithFrame:CGRectMake(10, 100, 200, 30)]; self.timer.delegate = self; // 記得遵守代理 self.timer.sceonds = 5; self.timer.layer.borderWidth = 1; self.timer.layer.cornerRadius = 5; self.timer.layer.borderColor = [UIColor orangeColor].CGColor; self.timer.label.font = [UIFont systemFontOfSize:14]; self.timer.label.textColor = [UIColor orangeColor]; [self.view addSubview:self.timer]; self.button = [[UIButton alloc] initWithFrame:CGRectMake(10, 150, 100, 40)]; self.button.layer.borderWidth = 1.0f; self.button.layer.borderColor = [UIColor blackColor].CGColor; [self.button setTitle:@"點(diǎn)擊" forState:UIControlStateNormal]; [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; [self.button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted]; [self.button setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled]; [self.view addSubview:self.button]; [self.button addTarget:self action:@selector(buttonEvent) forControlEvents:UIControlEventTouchUpInside]; } - (void)buttonEvent { // 啟動(dòng)倒計(jì)時(shí)的方法,啟動(dòng)之后設(shè)置button點(diǎn)擊失效 [self.timer timerStart]; self.button.enabled = NO; self.button.layer.borderColor = [UIColor grayColor].CGColor; } - (void)timerFinished:(Timer *)timer { // 計(jì)時(shí)完成之后,button恢復(fù)點(diǎn)擊 self.button.enabled = YES; self.button.layer.borderColor = [UIColor blackColor].CGColor; } @end
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- IOS開發(fā)代碼分享之用nstimer實(shí)現(xiàn)倒計(jì)時(shí)功能
- IOS實(shí)現(xiàn)驗(yàn)證碼倒計(jì)時(shí)功能(一)
- IOS關(guān)于大型網(wǎng)站搶購(gòu)、距活動(dòng)結(jié)束,剩余時(shí)間倒計(jì)時(shí)的實(shí)現(xiàn)代碼
- Swift實(shí)現(xiàn)iOS應(yīng)用中短信驗(yàn)證碼倒計(jì)時(shí)功能的實(shí)例分享
- IOS實(shí)現(xiàn)驗(yàn)證碼倒計(jì)時(shí)功能(二)
- ios 實(shí)現(xiàn)倒計(jì)時(shí)的兩種方式
- iOS中實(shí)現(xiàn)簡(jiǎn)單易懂秒殺倒計(jì)時(shí)/倒計(jì)時(shí)代碼
- IOS倒計(jì)時(shí)設(shè)置UIButton標(biāo)題title的抖動(dòng)問題
- iOS獲取驗(yàn)證碼倒計(jì)時(shí)效果
- iOS實(shí)現(xiàn)毫秒倒計(jì)時(shí)的方法詳解
相關(guān)文章
iOS自動(dòng)生成表格效果的實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了iOS自動(dòng)生成表格效果的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03iOS開發(fā)中使用UIScrollView實(shí)現(xiàn)無限循環(huán)的圖片瀏覽器
這篇文章主要介紹了iOS開發(fā)中使用UIScrollView實(shí)現(xiàn)無限循環(huán)的圖片瀏覽器的方法,感興趣的小伙伴們可以參考一下2016-03-03iOS長(zhǎng)按UIlabel實(shí)現(xiàn)可復(fù)制功能
在我們?nèi)粘5拈_發(fā)中經(jīng)常會(huì)遇到一些小需求,比如需要長(zhǎng)按控件來拷貝控件中得內(nèi)容,所以這篇文章跟大家分享下iOS中長(zhǎng)按UIlabel實(shí)現(xiàn)可復(fù)制功能的方法,有需要的朋友們可以參考借鑒。2016-09-09iOS實(shí)現(xiàn)簡(jiǎn)易的計(jì)算器
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)簡(jiǎn)易的計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01iOS App開發(fā)中通過UIDevice類獲取設(shè)備信息的方法
UIDevice最常見的用法就是用來監(jiān)測(cè)iOS設(shè)備的電量了,然后再實(shí)現(xiàn)電池狀態(tài)通知非常方便,除此之外還有傳感器等信息的獲取,這里我們就來總結(jié)一下iOS App開發(fā)中通過UIDevice類獲取設(shè)備信息的方法:2016-07-07