Enforce collectionView to have only 2 rows

后端 未结 3 1674
生来不讨喜
生来不讨喜 2020-12-06 22:14

I have to make one collection view so that irrespective of iphone size we have just 2 images in each row and also we need border between each row and column as shown in the

3条回答
  •  青春惊慌失措
    2020-12-06 22:59

    Try this code. Just a different approach.

         func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
    
         let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
         layout.sectionInset = UIEdgeInsets(top: 6, left: 4, bottom: 6, right: 4)
         layout.minimumInteritemSpacing = 04
         layout.minimumLineSpacing = 04
         layout.invalidateLayout()
         return CGSize(width: ((self.view.frame.width/2) - 6), height: ((self.view.frame.width / 2) - 6))
         }
    

    Output from above code on different devices.

提交回复
热议问题