title: UIcollectionview lagging while scrolling cells
body: <p>I am creating 7 cells using <code>UICollectionview</code>. When i scroll, the application works fine, but if i continue to scroll, it start to lag and the shadow(behind every cell) become more dark. </p>
  
  <p>I think that the cell that disappear from the screen is not deleted and when i return back the program recreate a new one in the same position of the oldest one. is there any solution?</p>
  
  <p>Screen before the scroll </p>
  
  <p><a href="https://ibb.co/dNQJ5k" rel="nofollow noreferrer">https://ibb.co/dNQJ5k</a></p>
  
  <p>Scree after the scroll  </p>
  
  <p><a href="https://ibb.co/kjDAJ5" rel="nofollow noreferrer">https://ibb.co/kjDAJ5</a></p>
  
  <p>here's the code</p>
  
  <pre><code>class menuController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
  
  @IBOutlet weak var coll_view: UICollectionView!
  
  var array = [String]()
  override  func viewDidLoad() {
      array = ["segue_menu_map", "segue_menu_camera"]
      coll_view.scrollToItem(at: IndexPath(item: 2, section: 0), at: .left, animated: true)
  }
  
  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return 7
  }
  
  func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
      return 1
  }
  
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) 
      let button = UIButton(type: .custom)
      button.frame = CGRect(x: 0, y: 0, width: cell.frame.width, height: cell.frame.height)
      button.layer.cornerRadius = 0.2*button.frame.width
      button.backgroundColor = UIColor.white
      button.layer.borderWidth = 2
      button.tag=indexPath.row
      button.layer.shadowColor = UIColor.lightGray.cgColor
      button.layer.shadowOpacity = 1.0
      button.layer.shadowOffset = CGSize(width: 0.4, height: 1.8)
      cell.clipsToBounds = false
      button.addTarget(self, action: #selector(collectionAction(sender:)), for: .touchUpInside)
      print([indexPath.row])
      //cell.backgroundColor = UIColor.gray
      button.setTitle(String(indexPath.row), for: .normal)
      button.setTitleColor(.black, for: .normal)
      cell.addSubview(button)
      return cell
  }
  
  
  
  func collectionAction( sender: UIButton) {
      if sender.tag &lt; 2{
      self.performSegue(withIdentifier: array[sender.tag], sender: nil)
      }
  
   }
  }
  </code></pre>
  
  <p>thanks in advance</p>