This article describes the different selection modes available in TKCalendar
The selection mode in TKCalendar
can be altered by using the selectionMode
property. The available options are:
TKCalendarSelectionModeNode
- No selection is allowed.TKCalendarSelectionModeSingle
- A single date can be selected.TKCalendarSelectionModeMultiple
- Different dates can be selected by tapping on them. A second tap will deselect the date.TKCalendarSelectionModeRange
- A range between two dates on the same page can be selected.Use the selectedDate
property to get or set the currently selected date in TKCalendar
when the single selection mode is used.
Use the selectedDates
property to get or set the selected dates when multiple selection mode is selected.
The selectedDatesRange
property is used to store the date range when this selection option is used.
You can determine whether a selection is changed by adopting TKCalendarDelegate
protocol:
- (void)calendar:(TKCalendar *)calendar didSelectDate:(NSDate *)date
{
NSLog(@"selected: %@", date);
}
func calendar(_ calenadr:TKCalendar, didSelect date: Date) {
print("selected: %@", date)
}
public override void DidSelectDate (TKCalendar calendar, NSDate date)
{
Console.WriteLine (String.Format ("{0}", date));
}
You can prevent TKCalendar
from selecting specific date by handling the calendar:shouldSelectDate:
- (BOOL)calendar:(TKCalendar *)calendar shouldSelectDate:(NSDate *)date
{
NSLog(@"Trying to select the unselectable: %@", date);
return ![TKCalendar isDate:self.unselectable
equalToDate:date
withComponents:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay
withCalendar:_calendarView.calendar];
}
func calendar(_ calenadr:TKCalendar, shouldSelect date: Date)->Bool {
print("Trying to select the unselectable: %@", date)
return !TKCalendar.isDate(self.unselectable!, equalTo: date, withComponents:[.year, .month, .day], with: calendarView.calendar)
}
public override bool ShouldSelectDate (TKCalendar calendar, NSDate date)
{
Console.WriteLine (String.Format ("Trying to select the unselectable {0}", date));
return !TKCalendar.IsDate (main.UnselectableDate, date, NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, main.CalendarView.Calendar);
}
Furthermore, the calendar:didDeselectDate:
is called when using multiple selection to notify for unselected dates:
- (void)calendar:(TKCalendar *)calendar didDeselectedDate:(NSDate *)date
{
NSLog(@"deselected: %@", date);
}
func calendar(_ calenadr:TKCalendar, didDeselectedDate date: Date) {
print("deselected: %@", date)
}
public override void DidDeselectedDate (TKCalendar calendar, NSDate date)
{
Console.WriteLine (String.Format ("{0}", date));
}