Home > Software design >  Collection View Stacking Items in Single Rows – Swift Xcode
Collection View Stacking Items in Single Rows – Swift Xcode

Time:01-24

Would someone please tell me why my collection view is stacking like this instead of side-by-side (until there's no more room and a new row has to be started)? I don't want them stacking with only one per row.

Collection View

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        claimSections.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as? ClaimTypeCollectionCell else {return UICollectionViewCell()}
        
        cell.claimTypeCollectionImage.image = claimSectionImages[indexPath.row]
        cell.claimTypeCollectionLabel.text = claimSections[indexPath.row]
        cell.frame.size.height = 135
        cell.frame.size.width = 135
        cell.layer.borderWidth = 2
        cell.layer.borderColor = UIColor.black.cgColor
        
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        if indexPath.row == 0 {
            // The Auto button was tapped -> load the auto page
            modelController.theClaimType = "Auto"
            modelController.isANewFile = true
            performSegue(withIdentifier: "claimTypeToFileSetupSegue", sender: self)
        } else {
            SCLAlertView().showNotice("COMING SOON!", subTitle: "This section is not yet available. It will be soon!")
        }
    }

CodePudding user response:

enter image description here

Scorll Direction -> Horizontal

CodePudding user response:

for arranging auto layout on your collectionViewCells you have to modify flowLayout on your collection view and set the size of cells.

  •  Tags:  
  • Related