Skip to content

Instantly share code, notes, and snippets.

@wdchris
Created May 18, 2020 17:40
Show Gist options
  • Save wdchris/65df03050531a88f6df56dd01ab1302c to your computer and use it in GitHub Desktop.
Save wdchris/65df03050531a88f6df56dd01ab1302c to your computer and use it in GitHub Desktop.
func numberOfSections(in collectionView: UICollectionView) -> Int {
return calendarRange.count
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return calendarRange[section].daysInMonth
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionView.elementKindSectionHeader:
let section = calendarRange[indexPath.section]
let date = CalendarManager.getDate(year: section.year, month: section.month)
let header = CalendarHeader.dequeue(from: collectionView, at: indexPath, forDate: date)
return header
default:
fatalError("Invalid element type")
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let section = calendarRange[indexPath.section]
let daysInSection = section.daysInMonth
let day = daysInSection - indexPath.item
let cell = CalendarCell.dequeue(from: collectionView, at: indexPath, forDay: day)
return cell
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment