·您现在的位置: 江北区云翼计算机软件开发服务部 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> 简单的倒计时效果

简单的倒计时效果

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

 

- (void)viewDidLoad {

    [super viewDidLoad];

    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerMethod:) userInfo:nil repeats:YES];

}

 

- (void)timerMethod:(NSTimer *)timer

{

//创建一个NSCalendar对象

    NSCalendar *calendar = [NSCalendar currentCalendar];

    NSDateComponents *Boom = [[NSDateComponents alloc] init];

    Boom.year = 2015;

    Boom.month = 7;

    Boom.day = 8;

    Boom.hour = 13;

    Boom.minute = 59;

    Boom.second = 30;

    //把目标时间装载入date

    NSDate *date = [calendar dateFromComponents:Boom];

    //得到当前时间

    NSDate *currentDate = [NSDate date];

    //用来得到具体的时差

    unsigned int flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;

    NSDateComponents *rub = [cal components:flags fromDate:currentDate toDate:date options:0];

 _Boom.text = [NSString stringWithFormat:@"💣💥⌚️%ld:%ld:%ld", d.hour, d.minute, d.second];

}