Reputation: 11
Please help me! I am using https://github.com/WenchaoD/FSCalendar in my project . I want to disable some dates after current date. I want only 28 dates will be enable after current days. Is it possible?
Upvotes: 0
Views: 2756
Reputation: 11
Yes you can set number of day, for this you have to set minimum and maximum date of FScalander and for this you have to implement below code into your view controller.
extension ViewController:FSCalendarDataSource
{
func minimumDate(for calendar: FSCalendar) -> Date {
return Date()
}
func maximumDate(for calendar: FSCalendar) -> Date {
var dateComponents:DateComponents = DateComponents()
dateComponents.day = 28
let currentCalander:Calendar = Calendar.current
return currentCalander.date(byAdding:dateComponents, to: Date())!
}
}
and Make sure don't forget connect datasource of FSCalander in your viewcontroller
Upvotes: 1
Reputation: 167
I think you want to enable some dates to be selectable you can use the following Delegate
extension YourView: FSCalendarDelegate, FSCalendarDataSource {
func calendar(_ calendar: FSCalendar, shouldSelect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool {
return yourDates.contains(where: { $0.startOfDay == date.startOfDay })
}
}
extension Date {
var startOfDay: Date {
return Calendar.current.startOfDay(for: self)
}
}
Upvotes: 0