skip to Main Content

The uicollectionview has n sections (say 1,2,3) that has m subsections (say 1.1,1.2 etc) which further branches into inner subsections (1.1.1, 1.1.2 etc) which finally has X no. of rows in it.

Like the layout in this picture

2

Answers


  1. Chosen as BEST ANSWER

    I've implemented this using UICollectionViewCompositionalLayout. Used the UICollectionViewCompositionalLayout { [self] (sectionNumber, environment) -> NSCollectionLayoutSection? in .... } closure to setup the layout items and group them vertically and horizontally to form the layout for the entire section.

    For reference -

    To create an individual item (H: 50, W: 50) -

    let item = NSCollectionLayoutItem(layoutSize: NSCollectionLayoutSize(widthDimension: .absolute(50), heightDimension: .absolute(50)))
    

    To create groups (Horizontal) -

    let group = NSCollectionLayoutGroup.horizontal(layoutSize:
                                                                        NSCollectionLayoutSize(widthDimension:
                                                                                .absolute(item.layoutSize.widthDimension.dimension * CGFloat((data.count))),
                                                                                               heightDimension:  .estimated(50)), subitem: item, count: (data.count))
    

    Group - vertical

     let subGroup = NSCollectionLayoutGroup.vertical(layoutSize:
                                                                NSCollectionLayoutSize(widthDimension:
                                                                        .absolute(CGFloat(width)),
                                                                                       heightDimension:
                                                                        .absolute(heightForIndividualItem * CGFloat(data.count))),
                                                            subitems: group)
            
    

  2. Why not just use three collection views and three screens?

    Tap on Section 1 creates second screen with collection view with sections Subsection 1 and Subsection 2.

    Then tap on Subsection 1 creates third screen with collection view with sections Row 1, Row 1, Row 1, Row 1.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search