title: ios - UICollectionView layout last row
body: <p>I am currently working on a <strong>UICollectionView</strong>. I have been looking all over SO and found several issues to this problem, but none of those had an answer to the problem. Maybe if i collect all the facts in one question here, one can provide a solution to this issue:</p>
  
  <p>If I have a collectionView with a simple UICollectionViewFlowLayout subclass, all works fine but the last row. I do <strong>everything with autoLayout</strong>. The cells align just fine, they fill out the row as soon as a new row starts. The only problem there is that <strong>the last row's layout</strong> is still as it would wait for another item to be added.</p>
  
  <p>Now, some code, here's my UICollectionViewFlow subclass:</p>
  
  <pre><code>@implementation SubCollectionViewFlowLayout
  - (instancetype)init {
      self = [super init];
      if (self) {
          self.estimatedItemSize = CGSizeMake(100, 100);
          self.minimumInteritemSpacing = 5.0f;
          self.minimumLineSpacing = 5.0f;
          self.scrollDirection = UICollectionViewScrollDirectionVertical;
      }
      return self;
  }
  </code></pre>
  
  <p>This is the whole subclassing. So it really is just basic.</p>
  
  <p>So when looking for another issue with this problem, i found the following SO Questions. The first one is exactly my probelm, the others seem to be similar.</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/24860754/uicollectionview-layout-of-last-cell">UICollectionView layout of last cell</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/26566911/uicollectionview-estimateditemsize-last-cell-is-not-aligned">UICollectionView estimatedItemSize - last cell is not aligned</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/31146480/uicollectionview-last-cell-not-aligned">UICollectionView last cell not aligned</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/34080257/last-item-in-uicollectionview-not-alligned-swift">Last item in UICollectionView not alligned - Swift</a></p></li>
  </ul>
  
  <p>I hope this is enough description for the problem, help is as always much appreciated.</p>