• 倒计时


    效果

    用法

    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
  • 相关阅读:
    win server 2012 服务器不能ping通
    Linux系统的文件目录结构
    怎样理解和识别 Linux 中的文件类型
    Linux(Centos 7)下安装Git并配置连接GitHub
    centos 7 下升级自带 sqlite3
    Pycharm项目上传到Github
    计算机存储单位:bit, Byte, KB, MB, GB, TB, PB, EB, ZB, BB
    ubuntu 删除命令
    influxDB 各个历史版本号,时间截止2020年9月27日
    使用Github做一个完全免费的个人网站
  • 原文地址:https://www.cnblogs.com/makingitbest/p/6491155.html
Copyright © 2020-2023  润新知