国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS倒計時的實現方法

2019-10-21 18:47:50
字體:
來源:轉載
供稿:網友

本文實例為大家分享了iOS倒計時的具體實現代碼,供大家參考,具體內容如下

效果

 iOS,倒計時

用法

1.導入Timer.h/.m文件

2.所需界面導入頭文件 #import “Timer.h”,其他設置參考源碼 

源碼

 github:https://github.com/makingitbest/CountDownTimer

細節

#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];  // 倒計時界面 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:@"點擊" 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 {  // 啟動倒計時的方法,啟動之后設置button點擊失效 [self.timer timerStart]; self.button.enabled = NO; self.button.layer.borderColor = [UIColor grayColor].CGColor;}- (void)timerFinished:(Timer *)timer { // 計時完成之后,button恢復點擊 self.button.enabled = YES; self.button.layer.borderColor = [UIColor blackColor].CGColor;}@end

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 固阳县| 兴安县| 吐鲁番市| 荆州市| 德钦县| 吉木萨尔县| 宜兴市| 金坛市| 将乐县| 绍兴市| 锦屏县| 罗田县| 汶上县| 宝兴县| 井陉县| 巴青县| 兴文县| 彰武县| 富裕县| 盐山县| 阳原县| 常山县| 涿州市| 顺平县| 白水县| 泽普县| 武鸣县| 南和县| 尖扎县| 榕江县| 新巴尔虎左旗| 济源市| 江永县| 浦北县| 名山县| 杭锦后旗| 武夷山市| 石柱| 准格尔旗| 米脂县| 苏州市|