Created
June 23, 2014 04:36
-
-
Save alex-zige/e3734363e97dcf5be6f5 to your computer and use it in GitHub Desktop.
UIDatePicker config with interval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(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