JPACalendar
extension CalendarViewController: JTACMonthViewDelegate
startDate: 캘린더 시작일
endDate: 캘린더 종료 일
numberOfRows: 디폴트는 6
calendar: calendar(): region/timezones.. default: ios calendar
generateInDates
generateOutDates

firstDayOfWeek: default: sun
hasStrictBoundaries

extension CalendarViewController: JTACMonthViewDelegate {
func calendar(_ calendar: JTACMonthView, willDisplay cell: JTACDayCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {
guard let cell = cell as? DateCollectionViewCell else {return}
cell.dateLabel.text = cellState.text
}
func calendar(_ calendar: JTACMonthView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTACDayCell {
guard let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: DateCollectionViewCell.identifier, for: indexPath) as? DateCollectionViewCell else {
return JTACDayCell()
}
cell.dateLabel.text = cellState.text
return cell
}
}
extension CalendarViewController: JTACMonthViewDataSource {
func configureCalendar(_ calendar: JTACMonthView) -> ConfigurationParameters {
formatter.dateFormat = "yyyy MM dd"
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale
let startDate = formatter.date(from: "2021 11 01")!
let endDate = Date()
return ConfigurationParameters(startDate: startDate, endDate: endDate)
}
}
func handleCellSelected(view: JTACDayCell?, cellSTate: CellState) {
guard let validCell = view as? DateCollectionViewCell else { return }
validCell.selectedView.cornerRounded(cornerRadius: 20)
if validCell.isSelected {
isSelectedDate = true
calendarView.allowsMultipleSelection = true
validCell.selectedView.isHidden = false
} else {
calendarView.allowsMultipleSelection = false
isSelectedDate = false
validCell.selectedView.isHidden = true
}
}
func calendar(_ calendar: JTACMonthView, didSelectDate date: Date, cell: JTACDayCell?, cellState: CellState, indexPath: IndexPath) {
print("didSelectDate: \(date), CellState: \(cellState)")
calendarView.allowsMultipleSelection = true
handleCellSelected(view: cell, cellSTate: cellState)
handleCelltextColor(view: cell, cellSTate: cellState)
print(cellState.date)
}
func calendar(_ calendar: JTACMonthView, didDeselectDate date: Date, cell: JTACDayCell?, cellState: CellState, indexPath: IndexPath) {
calendar.selectDates(calendar.selectedDates.filter({ $0 != date }))
handleCellSelected(view: cell, cellSTate: cellState)
handleCelltextColor(view: cell, cellSTate: cellState)
}
참고