title: Not able to display collection to half of size of the screen for every device ios
body: <p><a href="https://i.stack.imgur.com/zCXJo.jpg" rel="nofollow noreferrer">In Image their is lot os space between the two items of uiCollection view.And they are not display properly for every device size</a>I am trying to Display collection two items at one row but it doesn't display properly for every devices how can I split screen into two part in  swift.I have use several Constraint but it doesn't work
  I also have similar problem for UITableview.</p>
  <pre><code>import UIKit
  
  class MarketProduct: UIViewController {
  
      @IBOutlet weak var searchbar: UISearchBar!
      @IBOutlet weak var ItemCollectionView: UICollectionView!
      let productImages:[String]=[&quot;pulse&quot;,&quot;pulse&quot;,&quot;pulse&quot;,&quot;pulse&quot;,&quot;pulse&quot;,&quot;pulse&quot;,&quot;pulse&quot;,&quot;pulse&quot;,&quot;pulse&quot;,&quot;pulse&quot;,&quot;pulse&quot;];
      let productPrice:[String]=[&quot;$20000&quot;,&quot;$20000&quot;,&quot;$20000&quot;,&quot;$20000&quot;,&quot;$20000&quot;,&quot;$20000&quot;,&quot;$20000&quot;,&quot;$20000&quot;,&quot;$20000&quot;,&quot;$20000&quot;,&quot;$20000&quot;]
      let productDescription:[String]=[&quot;Server-side rendering with JavaScript libraries like React is where the server returns a ready to render HTML page and the JS scripts required to make the page interactive. The HTML is rendered immediately with all the static elements&quot;,&quot;Server-side rendering with JavaScript libraries like React is where the server returns a ready to render HTML page and the JS scripts required to make the page interactive. The HTML is rendered immediately with all the static elements&quot;,&quot;Server-side rendering with JavaScript libraries like React is where the server returns a ready to render HTML page and the JS scripts required to make the page interactive. The HTML is rendered immediately with all the static elements&quot;,&quot;Server-side rendering with JavaScript libraries like React is where the server returns a ready to render HTML page and the JS scripts required to make the page interactive. The HTML is rendered immediately with all the static elements&quot;,&quot;Server-side rendering with JavaScript libraries like React is where the server returns a ready to render HTML page and the JS scripts required to make the page interactive. The HTML is rendered immediately with all the static elements&quot;,&quot;Server-side rendering with JavaScript libraries like React is where the server returns a ready to render HTML page and the JS scripts required to make the page interactive. The HTML is rendered immediately with all the static elements&quot;,&quot;Server-side rendering with JavaScript libraries like React is where the server returns a ready to render HTML page and the JS scripts required to make the page interactive. The HTML is rendered immediately with all the static elements&quot;,&quot;Server-side rendering with JavaScript libraries like React is where the server returns a ready to render HTML page and the JS scripts required to make the page interactive. The HTML is rendered immediately with all the static elements&quot;,&quot;Server-side rendering with JavaScript libraries like React is where the server returns a ready to render HTML page and the JS scripts required to make the page interactive. The HTML is rendered immediately with all the static elements&quot;,&quot;Server-side rendering with JavaScript libraries like React is where the server returns a ready to render HTML page and the JS scripts required to make the page interactive. The HTML is rendered immediately with all the static elements&quot;,&quot;Server-side rendering with JavaScript libraries like React is where the server returns a ready to render HTML page and the JS scripts required to make the page interactive. The HTML is rendered immediately with all the static elements&quot;]
      let productAge:[String]=[&quot;2 years old&quot;,&quot;2 years old&quot;,&quot;2 years old&quot;,&quot;2 years old&quot;,&quot;2 years old&quot;,&quot;2 years old&quot;,&quot;2 years old&quot;,&quot;2 years old&quot;,&quot;2 years old&quot;,&quot;2 years old&quot;,&quot;2 years old&quot;]
      let locations:[String]=[&quot;pune&quot;,&quot;pune&quot;,&quot;pune&quot;,&quot;pune&quot;,&quot;pune&quot;,&quot;pune&quot;,&quot;pune&quot;,&quot;pune&quot;,&quot;pune&quot;,&quot;pune&quot;,&quot;pune&quot;]
      
      override func viewDidLoad() {
          super.viewDidLoad()
          searchbar.searchTextField.backgroundColor = .white
          searchbar.layer.borderWidth = 1
          searchbar.layer.borderColor = UIColor.black.cgColor
          searchbar.layer.cornerRadius = 15
          searchbar.layer.masksToBounds = true
   
      }
      
  }
  extension MarketProduct:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout
  {
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          productImages.count
      }
      
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          let cell = ItemCollectionView.dequeueReusableCell(withReuseIdentifier:&quot;ItemCell&quot;, for: indexPath) as!  Items
          cell.itemImage.image = UIImage(named: productImages[indexPath.row])
          cell.PriceLabel.text = productPrice[indexPath.row]
          cell.descriptionLabel.text = productDescription[indexPath.row]
          cell.itemLocation.text = locations[indexPath.row]
          cell.layer.cornerRadius = 20
          cell.layer.borderWidth = 1
          cell.layer.borderColor = UIColor.blue.cgColor
          return cell
      }
      
      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
          
  //          let height = collectionView.frame.height
  //            let width  = collectionView.frame.width
  //            return CGSize(width: width, height: height)
  //          let height = view.frame.size.height
            let width = view.frame.size.width
        
            // in case you you want the cell to be 40% of your controllers view
          return CGSize(width: width * 0.4, height: 360)
  
          
  
      }
      
      
      
      
  }
  </code></pre>