Skip to content

Instantly share code, notes, and snippets.

@wdchris
Last active May 18, 2020 17:31
Show Gist options
  • Save wdchris/0ffc270571e8eb6636c06d154a2cb685 to your computer and use it in GitHub Desktop.
Save wdchris/0ffc270571e8eb6636c06d154a2cb685 to your computer and use it in GitHub Desktop.
class CalendarHeader: UICollectionReusableView {
@IBOutlet weak var monthLabel: UILabel!
static let identifier = "calendarHeader"
static func register(with collectionView: UICollectionView) {
collectionView.register(UINib.init(nibName: "CalendarHeader", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader , withReuseIdentifier: identifier)
}
static func dequeue(from collectionView: UICollectionView, at indexPath: IndexPath, forDate date: Date) -> CalendarHeader {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: identifier, for: indexPath) as? CalendarHeader ?? CalendarHeader()
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_GB")
dateFormatter.setLocalizedDateFormatFromTemplate("MMMM yyyy")
header.monthLabel.text = dateFormatter.string(from: date)
return header
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment