我需要你帮助 UIProgressView。
我需要将我的进度视图从当前日期更新到我选择的结束日期。
此方法仅更新标签并显示结束时间循环还剩多少时间。
-(void)updateProgressDate {
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int units = NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [cal components:units fromDate:[NSDate date] toDate:destDate options:0];
[_dateLabel setText:[NSString stringWithFormat:@"%d%c %d%c %d%c %d%c %d%c", [components month], 'm', [components day], 'd', [components hour], 'h', [components minute], 'm', [components second], 's']];
}
-(void)viewDidLoad {
destDate = [NSDate dateWithTimeIntervalSince1970:1369342800];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateProgressDate) userInfo:nil repeats:YES];
}
我如何将 NSDateComponents 实现到 UIProgressView?
谢谢
更新:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//1369342800
currentDate = [NSDate date];
destDate = [NSDate dateWithTimeIntervalSince1970:1369342800];
timeRemain = [destDate timeIntervalSinceDate:currentDate];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateProgressDate) userInfo:nil repeats:YES];
}
-(void)updateProgressDate {
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int units = NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [cal components:units fromDate:currentDate toDate:destDate options:0];
//[_dateLabel setText:[NSString stringWithFormat:@"%d%c %d%c %d%c %d%c", [components month], 'm', [components day], 'd', [components hour], 'h', [components minute], 'm']];
[_dateLabel setText:[NSString stringWithFormat:@"%dm %dd %dh %dm", [components month], [components day], [components hour], [components minute]]];
[_progDate setProgress:_progDate.progress = timeRemain]; // here i did += -= right now my progress bar filled but that's not right. my circle 24 day until 24 day next month
//据我所知,一个月的 1% 是 0.03 对吗?
NSLog([NSString stringWithFormat:@"Remain time: %dm %dd %dh %dm"], timeRemain);
}
所以标签很好,但进度条总是满的。
我哪里错了?
谢谢