我正在嘗試此代碼,但它不起作用。 謝謝大家。 我正在使用uidatepicker與select minimumDate。但在datepicker swift 2.0中需要額外的15天。如何將datepicker當前日期限制在swift 2.0中的下一個15天
override func viewDidLoad() {
let datePickerView:UIDatePicker = UIDatePicker()
datePickerView.datePickerMode = UIDatePickerMode.Date
sender.inputView = datePickerView
datePickerView.minimumDate = datePickerView.date
//datePickerView.maximumDate = datePickerView.date
datePickerView.addTarget(self, action: #selector(BookAppointmentView.datePickerValueChanged(_:)), forControlEvents: UIControlEvents.ValueChanged)
}
func datePickerValueChanged(sender:UIDatePicker)->NSDate {
let baseDate:NSDate = NSDate()
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
DatePickerField.text = dateFormatter.stringFromDate(sender.date)
print("date of bookAppointment\(DatePickerField.text!)")
return newDate!
}
datePickerView.maximumDate = NSDate()。dateByAddingDays(15)! –
感謝它爲我工作.... –