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