0

I am Trying to resize my cell based on the screen size so that there is only 2 cell per row. I am using the code

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
       return CGSize(width: MyCollectionView.bounds.width / 2.2, height: MyCollectionView.bounds.height / 5.5)    
}

This works and resizes to the different screen sizes. I run it on. however when you rotate into landscape mode it displays more than two cells per row.

Nazmul Hasan
  • 8,494
  • 5
  • 44
  • 64
c3pNoah
  • 65
  • 1
  • 10
  • Possible duplicate of [UICollectionView - resizing cells on device rotate - Swift](http://stackoverflow.com/questions/34132766/uicollectionview-resizing-cells-on-device-rotate-swift) – Nazmul Hasan Apr 29 '17 at 19:46

1 Answers1

0

If The container of MyCollectionView is self.view then plz give a try to this . .

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: self.view.frame.width / 2.2 , height: MyCollectionView.bounds.height / 5.5)
}
Christian Ascone
  • 917
  • 6
  • 14
roy
  • 6,039
  • 3
  • 25
  • 36