Compositional Layout IOS 13 Group background color

Viewed 1928

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.

1 Answers

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)
Related