简单的倒计时效果

 

- (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];

}

 

posted @ 2015-07-08 14:22  偷窃者  阅读(284)  评论(0编辑  收藏  举报