簡單的倒計時效果,簡單倒計時效果
- (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:@"