Dayview Limit the calender for min and max dates swift Calenderkit

 Problem:

I'm using calenderkit and KDCalender in my project.I want to limit the calender with min and maxdates user can able to select.


Solution: 

You cannot be able to set the min and max dates in calenderkit.Instead of you can restrict the user to select the date you can limit.

extension MyVC:DayViewDelegate {

    func eventsForDate(_ date: Date) -> [CalendarKit.EventDescriptor] {

        let newDate = date.localDate()

        dateSelected(date: newDate)

        self.calenderView.setDisplayDate(newDate)

        return []

    }

    

    func dayView(dayView: CalendarKit.DayViewdidMoveTo date: Date) {

        if date<Date() {

            self.weekView.dayHeaderView.dateSelectorDidSelectDate(Date())

        } else if date>Date().addDays(daysToAdd90) {

            self.weekView.dayHeaderView.dateSelectorDidSelectDate(Date().addDays(daysToAdd90))

        }

    }

}



extension MyVCCalendarViewDelegateCalendarViewDataSource {


    func calendar(_ calendar: CalendarViewcanSelectDate date: Date) -> Bool {

        if date<Date() || date>Date().addDays(daysToAdd90){

            return false

        } else {

            return true

        }

    }


    func startDate() -> Date {

        var dateComponents = DateComponents()

        dateComponents.month = -1

        let today = Date()

        let threeMonthsAgo = self.calenderView.calendar.date(byAdding: dateComponents, to: today)

        return threeMonthsAgo!

    }

    

    func endDate() -> Date {

        var dateComponents = DateComponents()

        dateComponents.day = 90

        let today = Date()

        let threeMonthsnow = self.calenderView.calendar.date(byAdding: dateComponents, to: today)

        return threeMonthsnow!

    }

}

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift