在网上搜查倒计时可以有2种方法 一种使用NStimer
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];
- (void)timerFireMethod:(NSTimer *)timer
{
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setYear:[_year intValue]];
[components setMonth:[_month intValue]];
[components setDay:[_day intValue]];
[components setHour:0];
[components setMinute:0];
[components setSecond:0];
NSDate *fireDate = [calendar dateFromComponents:components];//目标时间
NSDate *today = [NSDate date];//当前时间
unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *d = [calendar components:unitFlags fromDate:today toDate:fireDate options:0];//计算时间差
if ([d second] < 0 || [d hour] < 0 ||[d minute] < 0 || [d day] < 0) {
_timeLabel.text = @"";//倒计时显示
}else{
_timeLabel.text = [NSString stringWithFormat:@"%.2ld days %.2ld:%.2ld:%.2ld", (long)[d day], (long)[d hour], (long)[d minute], (long)[d second]];//倒计时显示
}
}
另一种 是用GCD通过秒来倒计时 可以用到验证消息
(void)startTime{
}
接下来是自己用nstimer自己封装了一个label 来多重创建 这样可以方便很多 不知道怎么上传代码 你们自己想把