In UICollectionView, I want to give the whole section a uniform background color, instead of for a single cell or for the whole collection view.
I don't see any delegate method to do that, any suggestions?
The new UICollectionViewCompositionalLayout
introduced in iOS 13 have a property named decorationItems
for adding decoration items conveniently, which you could use to add a background for the section.
let section = NSCollectionLayoutSection(group: group) section.decorationItems = [ NSCollectionLayoutDecorationItem.background(elementKind:"your identifier") ]
The idea is to override UICollectionViewLayoutAttributes to add a color attribute. And then override UICollectionReusableView apply the color to the view background.
https://github.com/strawberrycode/SCSectionBackground
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With