I was trying to find if there is an approach we can use to give background color to a group while using compositional layout. I tried to find a direct API that i can use but didn't find anything.
For those looking for the answer, here you go.
let sectionBackgroundDecoration = NSCollectionLayoutDecorationItem.background(
elementKind: FollowingCollectionViewController.sectionBackgroundDecorationElementKind)
section.decorationItems = [sectionBackgroundDecoration]
let layout = UICollectionViewCompositionalLayout(section: section)
layout.register(
SectionBackgroundDecorationView.self,
forDecorationViewOfKind: FollowingCollectionViewController.sectionBackgroundDecorationElementKind)
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