ios – A number of column structure with assortment view compositional structure


I’m changing some furry assortment view code (scroll views with embedded stack views, assortment views, desk views, and so forth.) to a single assortment view with compositional structure. However I’m having troubles with “two column” structure when utilizing the depend parameter.

To experiment, I downloaded Apple’s Implementing Trendy Assortment Views pattern, appeared on the Create a Column Structure code, which has this instance:

extension TwoColumnViewController {
    /// - Tag: TwoColumn
    func createLayout() -> UICollectionViewLayout {
        let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
                                              heightDimension: .fractionalHeight(1.0))
        let merchandise = NSCollectionLayoutItem(layoutSize: itemSize)

        let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
                                               heightDimension: .absolute(44))
        let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitem: merchandise, depend: 2)
        let spacing = CGFloat(10)
        group.interItemSpacing = .mounted(spacing)

        let part = NSCollectionLayoutSection(group: group)
        part.interGroupSpacing = spacing
        part.contentInsets = NSDirectionalEdgeInsets(prime: 0, main: 10, backside: 0, trailing: 10)

        let structure = UICollectionViewCompositionalLayout(part: part)
        return structure
    }
}

Of their demo app, you get there by navigating to “Compositional Structure” » “Getting Began” » “Two-Column Grid”. Anyway, this yields:

enter image description here

OK, that’s advantageous.

However in iOS 16, horizontal(layoutSize:subitem:depend:) is deprecated:

enter image description here

And in the event you exchange it with horizontal(layoutSize:repeatingSubitem:depend:), you get a structure like the next (the place you can’t even scroll to the correct to see the cells offscreen):

enter image description here

How do you get columnar output in iOS 16 and later?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles