how to hide previous date and month in iOS using swift 3?

1.9k Views Asked by At

i am using the helper libaray "WWCalendarTimeSelector" GitHub link :- https://github.com/weilsonwonder/WWCalendarTimeSelector I have a date for registration of user and it's 29/9/2017. Now I want to only enable dates between next date, month and year.

when starting date select and future date select other date disable for example starting date :- 29/09/2017 and future date select 02/10/2017 Seeing the date after that, you will be disable... How can I do that ? please help....

@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
    }

enter image description here enter image description here

1

There are 1 best solutions below

0
prodeveloper On

You need to use WWCalendarTimeSelectorShouldSelectDate method for disabling the dates/date range you need. The below example may help you

    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
        }
    }

You can use your own date range in the above example