title: Remove inset spacing at bottom of UICollectionView
body: <p>I'm really in need of some help here. I've been trying for a few days but can't seem to fix it...</p>
  
  <p>I'm trying to lay out images in a <code>UICollectionView</code> grid style, with scrolling disabled. So I have 4 images/cells, and I'm trying to completely fill the <code>UICollectionView</code> with these images with 1 spacing between them.</p>
  
  <p><strong>The problem</strong>, however is that the spacing between the cells is split between center and the bottom. </p>
  
  <p>I've noticed that when changing the <code>scrollDirection</code> of the UICollectionView from vertical to horizontal, the problem still exists, but just changes direction too, so I'm guessing it has something to do with that.</p>
  
  <p><strong>example:</strong>
  <a href="https://i.stack.imgur.com/eZ7Qp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eZ7Qp.jpg" alt=""></a></p>
  
  <p>code:</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
  
          if isInFeed &amp;&amp; self.postImages!.count &gt; 1 {
  
              guard let flowLayout = collectionViewLayout as? UICollectionViewFlowLayout else {
                  return CGSize()
              }
              flowLayout.minimumInteritemSpacing = 1
              flowLayout.minimumLineSpacing = 1
  
              switch (self.postImages!.count) {
  
              case 2:
                  // we split the collectionView into 2 parts (+ 2*0.5 spacing)
                  return CGSize(width: (self.collectionView!.bounds.width/2)-CGFloat(0.5), height: self.collectionView!.bounds.height)
  
              case 3:
  
                  // we split the collectionView into 3 parts, the first one taking up half, the other 2 images taking up 1/4th (+spacing)
                  if indexPath.row == 0 { return CGSize(width: (self.collectionView!.bounds.width/2)-CGFloat(0.5), height: self.collectionView!.bounds.height) }
                  else { return CGSize(width: (self.collectionView!.bounds.width/2)-CGFloat(0.5), height: (self.collectionView!.bounds.height/2)-CGFloat(0.5)) }
  
              case 4:
              // we split the collectionView into 4 parts (1/4th + spacing)
  
  
  //                if indexPath.section == 0 { return CGSize(width: (self.collectionView!.bounds.width/2)-CGFloat(0.5), height: (self.collectionView!.bounds.height/2)-CGFloat(1))}
  //                else {return CGSize(width: (self.collectionView!.bounds.width/2)-CGFloat(0.5), height: (self.collectionView!.bounds.height/2)-CGFloat(0))}
  
                  return CGSize(width: (self.collectionView!.bounds.width/2)-CGFloat(0.5), height: (self.collectionView!.bounds.height/2)-CGFloat(0.5))
  
              default: break
              }
          }
          // If not in Feed or just one image, take up entire collectionView
          return CGSize(width: self.collectionView!.bounds.width, height: self.collectionView!.bounds.height)
      }
  </code></pre>
  
  <p>I also tried subclassing <code>UICollectionViewLayout</code> and <code>UICollectionViewFlowLayout</code>, but without success, I've read Apple's documentation, but that doesn't seem to help much.</p>
  
  <p>Hope this explains the problem clearly, I'd be happy to elaborate.
  Have a great day!</p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>I changed the scroll direction from vertical to horizontal and added 2 extra calculated spacing to each cell just to show off what happens if I do that. </p>
  
  <p><a href="https://i.stack.imgur.com/25DeO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/25DeO.png" alt="example2"></a></p>
  
  <p><strong>Edit 2:</strong></p>
  
  <p>Finally managed to fix it! (altough not as clean as I'd like it, it does work now)
  I put the following code inside of the <code>collectionViewLayout</code> method:</p>
  
  <pre><code>if indexPath.section == 0 {
       flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 1 * UIScreen.main.scale)
   } else {
       flowLayout.sectionInset = UIEdgeInsets.zero
   }
  </code></pre>
  
  <p>Big thanks to everyone trying to help out!</p>