cj.whitaker
(Christian Whitaker)
1
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.

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!")
}
}
mattcurtis
(Matt Curtis)
2
Because the cell's UIView.frame property isn't what controls how the UICollectionView determines how to layout cells. For information on how to configure layout in the way you intended, try the advice and demo project in the Implementing Modern Collection Views guide.
1 Like
cj.whitaker
(Christian Whitaker)
3
Thank you for the explanation and reference!