#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
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有