title: UICollectionView equal cell spacing
body: <p>I am displaying several images in a collection view. They are all the same orientation (landscape) except for one, which is portrait (see image below): </p>
  
  <p><a href="https://i.stack.imgur.com/hvZx0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hvZx0.png" alt="enter image description here"></a></p>
  
  <p>I am trying to make the portrait image more centered, so that everything is evenly spaced. Any ideas on how to do this? </p>
  
  <p>PhotoGalleryViewController.swift: </p>
  
  <pre><code>override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return images.count
  }
  
  override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! PhotoGalleryCell
  
      let image = UIImage(named: images[indexPath.row])
      cell.imageView.image = image
      cell.captionLabel.text = captions[indexPath.row]
      return cell
  }
  
  func collectionView(_ collectionView: UICollectionView,
                      layout collectionViewLayout: UICollectionViewLayout,
                      sizeForItemAtIndexPath indexPath: NSIndexPath) -&gt; CGSize {
      var size = CGSize()
  
      if (indexPath.row == 3)
      {
          size = CGSize(width: 450, height: 600)
      }
      else {
          size = CGSize(width: 940, height: 600)
  
      }
      return size
  }
  </code></pre>