SWIFTstuff
SWIFTstuff

Reputation: 53

Making the height/width of.a UICollectionViewCell dependent of the screen size

I have three CollectionViews in a single ViewController. If I now set the constraints, the amount of cells per column changes and that ruins my application. Is there a special way - without constraints - to handle that?

Upvotes: 0

Views: 44

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100549

Implement

let scW = UIScreen.main.bounds.width
let scH = UIScreen.main.bounds.height

func collectionView(_ collectionView: UICollectionView, 
                  layout collectionViewLayout: UICollectionViewLayout, 
           sizeForItemAt indexPath: IndexPath) -> CGSize {

  if collectionView == col1 {
      return CGSize(width:<##>,height:<##>) // supply ratio of screen width/height
  }
  else ...
  ...
}

Upvotes: 1

Related Questions