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:DayViewD
func eventsForDate(_ date: Date) -> [CalendarKit.EventDescriptor] {
let newDate = date.localDate()
dateSelected(date: newDate)
self.calenderView.setDisplayDa
return []
}
func dayView(dayView: CalendarKit.DayView, didMoveTo date: Date) {
if date<Date() {
self.weekView.dayHeaderView.da
} else if date>Date().addDays(daysToAdd: 90) {
self.weekView.dayHeaderView.da
}
}
}
extension MyVC: CalendarViewDelegate, CalendarViewDataSource {
func calendar(_ calendar: CalendarView, canSelectDate date: Date) -> Bool {
if date<Date() || date>Date().addDays(daysToAdd: 90){
return false
} else {
return true
}
}
func startDate() -> Date {
var dateComponents = DateComponents()
dateComponents.month = -1
let today = Date()
let threeMonthsAgo = self.calenderView.calendar.dat
return threeMonthsAgo!
}
func endDate() -> Date {
var dateComponents = DateComponents()
dateComponents.day = 90
let today = Date()
let threeMonthsnow = self.calenderView.calendar.dat
return threeMonthsnow!
}
Comments
Post a Comment