3

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

Jayprakash Singh
  • 1,343
  • 3
  • 15
  • 28
  • So what you are saying is you want the dates after the one you select to be greyed out or somehow show that you can't choose those dates? – DemetrioProgramerOsorio Sep 29 '17 at 10:11
  • I see you have asked a similar question here -> [question](https://stackoverflow.com/questions/46465319/disabling-previous-date-month-year-jtapplecalendar-in-ios-using-swift-3-0) . It looks like you are still looking for a calendar library which can disable dates. Why don't you try the one i created here? -> [JTAppleCalendar](https://cocoapods.org/pods/JTAppleCalendar). I can show you how to set it up. I also have many video tutorials --> [Here](https://www.youtube.com/watch?v=wyh_DVFeH_w&list=PLpqJf39XekqyUG7dxcqGO0JNprryysv9Q). Simply skip the videos you dont need. Any questions just ask. – Just a coder Sep 30 '17 at 14:52
  • did you got the solution? – Lenin Jun 05 '18 at 05:01
  • Hi, i am getting this error when i try to set delegate Property 'delegate' not found on object of type 'WWCalendarTimeSelector *' any suggestion how to overcome? thanks in advance. – Dhanunjay Kumar Jun 28 '18 at 07:32

1 Answers1

0

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

prodeveloper
  • 943
  • 14
  • 22