Sunday, November 8, 2026
HomeiOS Developmentios - Autoresizing UICollectionView cells with background overlapping

ios – Autoresizing UICollectionView cells with background overlapping

[ad_1]

I have to create sections with grouped autoresizing cells. To attain the impact of grouping, I take advantage of background as a ornament merchandise. As I would like the background to go beneath the background of earlier part, I alter its contentInsets. Nonetheless, the ultimate outcome seems like this:
enter image description here

The part 2 containing Cells 3 and 4 is overlapping the background of part 1. If I add extra sections, there’s a sample, that each second part background overlaps the earlier part background.

That is how I setup my collectionView:

        collectionView.delegate = self
        collectionView.dataSource = self
        collectionView.register(DesignTestCollectionCell.self)
        collectionView.backgroundColor = Coloration.clear
        collectionView.alwaysBounceVertical = false
        collectionView.alwaysBounceHorizontal = false
        collectionView.showsHorizontalScrollIndicator = false
        collectionView.showsVerticalScrollIndicator = false
        collectionView.collectionViewLayout = createCompositionalLayout()

That is the code for including part background:

    func addSectionBackground(
        high: CGFloat = 0,
        main: CGFloat = 0,
        backside: CGFloat = 0,
        trailing: CGFloat = 0
    ) -> CompositionalSection {
        let backgroundItem = NSCollectionLayoutDecorationItem.background(
            elementKind: DecorationViewType.background.rawValue
        )

        backgroundItem.contentInsets = NSDirectionalEdgeInsets(
            high: high,
            main: main,
            backside: backside,
            trailing: trailing
        )

        decorationItems = [backgroundItem]
        return self
    }

Might you assist me discover a technique to power earlier part background to at all times overlap the next part background?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments