I need you help with UIProgressView.
I need update my progress view from current date to end date I choose should be.
This Method updates only label and shows how much time remain to end time circle.
-(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];
}
How I can implement NSDateComponents to UIProgressView?
Thanks
Updated:
- (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
//as I understand 1% of month it's 0.03 right?
NSLog([NSString stringWithFormat:@"Remain time: %dm %dd %dh %dm"], timeRemain);
}
so label is srill going ok, but progress bar always full.
Where I am wrong?
Thanks