Last active
May 18, 2020 17:31
-
-
Save wdchris/0ffc270571e8eb6636c06d154a2cb685 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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