Why my custom button in **CollectionView** load only into **last cell**?

How can i make that button load in all cells?

```
var editButton = UIButton()

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CollectionViewCellCard

    switch ColorSegment.selectedSegmentIndex {
      case 0:
        cell.CardView.backgroundColor = ColorArray[indexPath.row]
        cell.ColorName.text = ColorName[indexPath.row]
      case 1:
        cell.CardView.backgroundColor = CustomColorArray[indexPath.row]
        cell.ColorName.text = CustomColorName[indexPath.row]

        editButton.frame = CGRect(x:63, y:0, width:20,height:20)
        editButton.layer.cornerRadius = 10
        editButton.backgroundColor = UIColor.lightGray
        editButton.layer.setValue(indexPath.item, forKey: "index")
        editButton.setImage(UIImage(named: "CloseScan"), for: UIControlState.normal)
        editButton.addTarget(self, action: #selector(deleteCell), for: UIControlEvents.touchUpInside)
        cell.addSubview(editButton)
      default: print("error with switch statement for cell data")
    }
    return cell
}

```

[![](https://i.stack.imgur.com/h7toy.png)](https://i.stack.imgur.com/h7toy.png)

**Edit Button Function**

```
     if EditButton.currentTitle == "Edit" {
            EditButton.setTitle("Cancel", for: .normal)
            //DeleteButton.isHidden = false
     } else if EditButton.currentTitle == "Cancel" {
            EditButton.setTitle("Edit", for: .normal)
            //DeleteButton.isHidden = true
     }

```