Working with DatePicker with some restrictions on Date and Time
I am working with DatePicker and I want to set specific restrictions on the selection of Date Picker by user,I want the
start day of the week - tues开发者_如何学JAVAday
end day of the week - saturday
start time - 16:00:00
end time - 19:00:00
So friends please share your thoughts on this.
Whether we should use NSDateComponents.
You can use next properties of UIDatePicker
:
The minimum date that a date picker can show:
@property(nonatomic, retain) NSDate *minimumDate
The maximum date that a date picker can show:
@property(nonatomic, retain) NSDate *maximumDate
You can set maximum and minimum limit to UIDatePicker as given,
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM-dd-yyyy HH:mm:ss"];
NSDate *startDate = [dateFormatter dateFromString:@"04-16-1983 20:30:15"];
NSDate *endDate = [dateFormatter dateFromString:@"10-16-1983 10:20:30"];
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
[datePicker setMinimumDate:startDate];
[datePicker setMaximumDate:endDate];
Hope this will help you.
精彩评论