我需要你帮助UIProgressView。xcode set progressView结束日期
我需要更新我的进度视图从当前日期到我选择的结束日期应该是。
此方法只更新标签并显示剩余多少时间来结束时间圆。
-(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);
}
所以标签是srill会好的,但进度条总是满的。
我在哪里错了?
谢谢
感谢Anoop,但问题是这里在这一行:[_dateLabel的setText:[的NSString stringWithFormat :[“元件月”,“m”,“元件日”,“d”,“元件小时数”,“h” ',[组件分钟],'米',[组件秒],''']]; _progDate(我的uiprogressview)不能接受字符串。 – Anton 2013-04-27 08:29:17
@Anton:检查更新/编辑 – 2013-04-27 17:28:48
谢谢!我会尝试你的解决方案,并会更新你。 – Anton 2013-04-27 18:21:33