首页 > 学院 > 开发设计 > 正文

简单的倒计时效果

2019-11-14 18:44:21
字体:
来源:转载
供稿:网友

 

- (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:@"

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表