3

我正在使用帮助程序 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
    }

在此处输入图像描述 在此处输入图像描述

4

1 回答 1

0

您需要使用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
        }
    }

您可以在上面的示例中使用自己的日期范围

于 2018-09-01T05:54:51.113 回答