title: Swift: UICollectionView dynamic cells size in a 2 column grid based on odd or even no of items
body: <p>I am trying to implement a collection view where I have to load images from the API data. Challenge here is that my collection view is a 2 column grid and if the number of images are odd, then the first cell should span to full  row. Here is the design mock up I want</p>
  
  <p><a href="https://i.stack.imgur.com/W0Kvr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W0Kvr.png" alt="design mockup"></a></p>
  
  <p>So as per the mockup</p>
  
  <ul>
  <li>If items are even, then display them 2 in each row.</li>
  <li>If items are odd, display the first one to span the full row, and show the remaining spanning 2
  in each row.</li>
  </ul>
  
  <p>I am following this tutorial to create grid view but don't know how to achieve the designs in mockup</p>
  
  <p><a href="https://www.raywenderlich.com/136159/uicollectionview-tutorial-getting-started" rel="nofollow noreferrer">https://www.raywenderlich.com/136159/uicollectionview-tutorial-getting-started</a></p>
  
  <p>Any help would be appreciated. Thanks in advance.</p>