Skip to content

Instantly share code, notes, and snippets.

@IronLeash
Forked from alex-zige/gist:e3734363e97dcf5be6f5
Last active August 29, 2015 14:07
Show Gist options
  • Save IronLeash/40eab322fd2c42d6fe49 to your computer and use it in GitHub Desktop.
Save IronLeash/40eab322fd2c42d6fe49 to your computer and use it in GitHub Desktop.
-(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