我正在使用帮助器libaray“WWCalendarTimeSelector”GitHub链接: - https://github.com/weilsonwonder/WWCalendarTimeSelector我有一个用户注册日期,它是29/9/2017。现在我想只在下一个日期,月份和年份之间启用日期。
当开始日期选择和将来日期选择其他日期禁用例如开始日期: - 29/09/2017和未来日期选择02/10/2017看到之后的日期,您将被禁用...我该怎么做?请帮忙....
@IBAction func btnSelectClick(_ sender: Any) {
let selector = UIStoryboard(name: "WWCalendarTimeSelector", bundle: nil).instantiateInitialViewController() as! WWCalendarTimeSelector
selector.delegate = self
selector.optionCurrentDate = singleDate
selector.optionCurrentDates = Set(multipleDates)
selector.optionCurrentDateRange.setStartDate(multipleDates.first ?? singleDate)
selector.optionCurrentDateRange.setEndDate(multipleDates.last ?? singleDate)
selector.optionStyles.showDateMonth(true)
selector.optionStyles.showMonth(false)
selector.optionStyles.showYear(true)
selector.optionStyles.showTime(false)
present(selector, animated: true, completion: nil)
}
func WWCalendarTimeSelectorDone(_ selector: WWCalendarTimeSelector, date: Date) {
print("Selected \n\(date)\n---")
singleDate = date
dateLabel.text = date.stringFromFormat("d' 'MMMM' 'yyyy', 'h':'mma")
}
func WWCalendarTimeSelectorDone(_ selector: WWCalendarTimeSelector, dates: [Date]) {
print("Selected Multiple Dates \n\(dates)\n---")
if let date = dates.first {
singleDate = date
dateLabel.text = date.stringFromFormat("d' 'MMMM' 'yyyy', 'h':'mma")
}
else {
dateLabel.text = "No Date Selected"
}
multipleDates = dates
}
您需要使用WWCalendarTimeSelectorShouldSelectDate
方法来禁用所需的日期/日期范围。以下示例可能对您有所帮助
fileprivate var today: Date = Date()
func WWCalendarTimeSelectorShouldSelectDate(_ selector: WWCalendarTimeSelector, date: Date) -> Bool{
let order = NSCalendar.current.compare(today, to: date, toGranularity: .day)
if order == .orderedDescending{ {
//Date selection will be disabled for past days
return false
} else {
//Allows to select from today
return true
}
}
您可以在上面的示例中使用自己的日期范围