我需要你幫助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