I went through a lot of articles and documentation. Everywhere UICollectionViewCompositionalLayout is used alongside UICollectionViewDiffableDataSource.

supplementaryViewProvider is used to dequeue the supplementary view. But how to get it invoked while the layout is UICollectionViewFlowLayout.

1

There are 1 best solutions below

0
djaflienda On

You have to add boundarySupplementaryItems while configuring your NSCollectionLayoutSection. Something like:

let headerSize = NSCollectionLayoutSize(
    widthDimension: .fractionalWidth(1),
    heightDimension: YOUR_HEIGHT
)
let headerItem = NSCollectionLayoutBoundarySupplementaryItem(
    layoutSize: headerSize,
    elementKind: YOUR_HEADER_IDENTIFIER,
    alignment: .top
)
sectionItem.boundarySupplementaryItems = [headerItem]