开发者

Working with DatePicker with some restrictions on Date and Time

开发者 https://www.devze.com 2023-04-08 14:46 出处:网络
I am working with DatePicker and I want to set specific restrictions on the selection of Date Picker by user,I want the

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号