< 返回首页

标哥的笔记,是记录在日常学习技术和日常开发中那些年遇到过的坑!本站为新站,原"标哥的技术博客"中的文章会慢慢移到本站,欢迎收藏本站!
在使用本站过程中,有任何建议请联系标哥! 另,承接App开发、网站开发和微信小程序开发!欢迎联系我们


iOS一个API实现短信发送倒计时效果

 作者:标哥    发布日期:2017-01-12 23:35    阅读量:1568次
 

倒计时功能在很多场景下都有使用到的,相信很多朋友都遇到过吧!那么我们如何能快速地实现呢?

实现代码

__block NSUInteger count = 60;
[NSTimer hyb_scheduledTimerWithTimeInterval:1 count:60 callback:^(NSTimer *timer) {
    if (count <= 1) {
      [self.codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
      self.codeButton.enabled = YES;
      [self.codeButton setTitleColor:kRGB(41, 119, 244)
                               forState:UIControlStateNormal];
      self.codeButton.backgroundColor=kWhiteColor;
    } else {
      [self.codeButton setTitle:[NSString stringWithFormat:@"%lds后获取", --count]
                       forState:UIControlStateNormal];
     [self.codeButton setTitleColor:kHexRGB(0x666666)forState:UIControlStateNormal];
     self.codeButton.backgroundColor=kHexRGB(0xdddddd);
      self.codeButton.enabled = NO;
    }
}];


承接:ThinkPHP项目开发、网站项目开发、微信项目开发、微信小程序项目开发、App开发,欢迎联系标哥QQ632840804