From 2ac43d8e33c61d6dfedbf1c4b0a425e8cfed3315 Mon Sep 17 00:00:00 2001 From: bekki Date: Thu, 17 Jun 2021 06:22:30 -0600 Subject: [PATCH] Method to programmatically deselect the selected color --- IGColorPicker/Classes/View/ColorPickerView.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/IGColorPicker/Classes/View/ColorPickerView.swift b/IGColorPicker/Classes/View/ColorPickerView.swift index 249ae59..9b925bd 100644 --- a/IGColorPicker/Classes/View/ColorPickerView.swift +++ b/IGColorPicker/Classes/View/ColorPickerView.swift @@ -152,7 +152,17 @@ open class ColorPickerView: UIView, UICollectionViewDelegate, UICollectionViewDa } - + public func deselectSelectedColor(animated: Bool) { + guard let selectedIndex = _indexOfSelectedColor else { return } + + let index = IndexPath(item: selectedIndex, section: 0) + _indexOfSelectedColor = nil + + guard let colorPickerCell = collectionView.cellForItem(at: index) as? ColorPickerCell else { return } + + colorPickerCell.checkbox.setCheckState(.unchecked, animated: animated) + } + // MARK: - UICollectionViewDataSource public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {