简体   繁体   中英

Compositional Layout IOS 13 Group background color

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM