UICollectionView.SupplementaryRegistration
A registration for the collection view’s supplementary views.
Declaration
struct SupplementaryRegistration<Supplementary> where Supplementary : UICollectionReusableViewOverview
Use a supplementary registration to register supplementary views, like headers and footers, with your collection view and configure each view for display. You create a supplementary registration with your supplementary view type and data item type as the registration’s generic parameters, passing in a registration handler to configure the view. In the registration handler, you specify how to configure the content and appearance of that type of supplementary view.
The following example creates a supplementary registration for a custom header view subclass.
let headerRegistration = UICollectionView.SupplementaryRegistration
<HeaderView>(elementKind: "Header") {
supplementaryView, string, indexPath in
supplementaryView.label.text = "\(string) for section \(indexPath.section)"
supplementaryView.backgroundColor = .lightGray
}After you create a supplementary registration, you pass it in to dequeueConfiguredReusableSupplementary(using:for:), which you call from your data source’s supplementaryViewProvider.
dataSource.supplementaryViewProvider = { collectionView, elementKind, indexPath in
return collectionView.dequeueConfiguredReusableSupplementary(using: headerRegistration,
for: indexPath)
}You don’t need to call register(_:forSupplementaryViewOfKind:withReuseIdentifier:) or register(_:forSupplementaryViewOfKind:withReuseIdentifier:). The registration occurs automatically when you pass the supplementary view registration to dequeueConfiguredReusableSupplementary(using:for:).