我有一个UIDatePicker,我希望将最小和最大日期范围设置为当周的周四到周三,我该如何设置? 选择器日期是日期选择器,而日期选择器文本字段是文本字段
pickerDate.datePickerMode = UIDatePickerMode.Date
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd MMM yyyy"
datePickerTextField.text = dateFormatter.stringFromDate(pickerDate.date)
答案 0 :(得分:0)
我会尝试以下方法:
NSCalendar
NSCalendarUnit.WeekOfYear
NSCalendarUnit.Weekday
答案 1 :(得分:0)
我想你想要这样的东西。
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDate *currentDate = [NSDate date];
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay: -7];
NSDate *minDate = [calendar dateByAddingComponents:comps toDate:currentDate options:0];
[datePicker setMaximumDate:currentDate];
[datePicker setMinimumDate:minDate];