I\'m working on a project that uses an UICollectionView
to show several albums. The items show fine, but now I want to show an header above the first section.
for SWIFT 3 & SWIFT 4
self.collectionView.register(UINib(nibName: "SectionCollectionReusableView", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "SectionCollectionReusableView")
self.collectionView.fs_width = self.collectionView.bounds.width
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 70, left: 40, bottom: 0, right: 0)
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0
layout.estimatedItemSize = CGSize(width: 350, height: 140)
layout.scrollDirection = .horizontal
layout.headerReferenceSize = CGSize(width: self.collectionView.bounds.size.width, height: 60)
layout.sectionHeadersPinToVisibleBounds = true
self.collectionView!.collectionViewLayout = layout
You have to add this to ViewDidLoad, and notice the
layout.headerReferenceSize = CGSize(width: self.collectionView.bounds.size.width, height: 60)
This will make the header Section Layouts
and Thanks @Guido Hendriks, and all I have got the insight from their answer as well