Skip to content

Instantly share code, notes, and snippets.

@alex-zige
Created June 23, 2014 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alex-zige/e3734363e97dcf5be6f5 to your computer and use it in GitHub Desktop.
Save alex-zige/e3734363e97dcf5be6f5 to your computer and use it in GitHub Desktop.
UIDatePicker config with interval
-(void)configDatePicker:(UIDatePicker *)datePicker{
datePicker.backgroundColor = [UIColor whiteColor];
// Round Default date with 15 mins interval
NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:NSMinuteCalendarUnit fromDate:[NSDate date]];
NSInteger minutes = [dateComponents minute];
NSInteger minutesRounded =roundf((float)minutes / (float)30 + 0.5) * 30;
NSDate *roundedDate = [[NSDate alloc] initWithTimeInterval:60.0 * (minutesRounded - minutes) sinceDate:[NSDate date]];
[datePicker setMinimumDate:roundedDate];
// Set interval
datePicker.minuteInterval = 30;
[datePicker addTarget:self action:@selector(updateMeetingDateTextField:) forControlEvents:UIControlEventValueChanged];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment