title: collectionview grid layout issue with different devices
body: <p>Hello i am creating App using <code>Swift</code> and i am creating grid view using <code>Collectionview</code> but i got different output on different devices here is the code for populating and setting layout of collectionview</p>
  <pre><code>var imageArray = [UIImage]()
  var nameArray = [&quot;General album&quot;,&quot;Videos&quot;,&quot;New album&quot;,&quot;Custom name album&quot;]
  private var numberOfItemsInRow = 2
  private var minimumSpacing = 10
  private var edgeInsetPadding = 10
  
  extension GalleryViewController:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return imageArray.count
      }
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: &quot;Cell&quot;, for: indexPath) as! GalleryCollectionViewCell
          cell.imgView.image = imageArray[indexPath.row]
          cell.lblName.text = nameArray[indexPath.row]
          return cell
      }
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -&gt; UIEdgeInsets {
          let inset = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
          edgeInsetPadding = Int(inset.left+inset.right)
          return inset
      }
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -&gt; CGFloat {
          return CGFloat(minimumSpacing)
      }
      
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -&gt; CGFloat {
          return CGFloat(minimumSpacing)
      }
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
          let width = (Int(UIScreen.main.bounds.size.width) - (numberOfItemsInRow - 1) * minimumSpacing - edgeInsetPadding) / numberOfItemsInRow
          return CGSize(width: width, height: width)
      }
  }
  </code></pre>
  <p>from this code i am not able to achive exact grid layout so i tried below code</p>
  <pre><code>func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
          let padding: CGFloat =  50
          let collectionViewSize = collectionView.frame.size.width - padding
  
          return CGSize(width: collectionViewSize/2, height: collectionViewSize/2)
      }
  </code></pre>
  <p>I got this code from this link:
  <a href="https://stackoverflow.com/questions/51818189/display-uicollectionview-with-2-columns-of-equal-size-square-cells">Display UICollectionView with 2 columns of equal size square cells</a></p>
  <p>but i am not able to achive exact grid layout its changed based on device i am sharing two screen shot</p>
  <hr />
  <p>iPhone 11 Max Pro screen shot:</p>
  <p><a href="https://i.stack.imgur.com/mF0DI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mF0DI.png" width="320" /></a></p>
  <hr />
  <p>iPhone 7 Screen Shot:</p>
  <p><a href="https://i.stack.imgur.com/pPLty.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pPLty.png" width="320" /></a></p>
  <p>in iphone 7 i am getting layout perfect but on iPhone 11 Max Pro i am not getting perfect any solution? than please help me</p>