【发布时间】:2020-02-27 12:01:58
【问题描述】:
我必须为 UIButton 应用边框,它的颜色与 UIButton 背景颜色匹配,它工作正常,但是当我重新加载集合视图时,它适用于其他按钮,然后重新加载它适用于其他按钮。假设如果集合视图重新加载 3 次,那么它将边框应用于 3 个错误的按钮,它应该只应用那些背景颜色与颜色变量颜色匹配的按钮
注意:- 一次只有一个按钮可以有边框。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ChromazonColorCell", for: indexPath) as! ChromazonColorCell
cell.configureData(data: colorSource[indexPath.row])
cell.cellColorButton.tag = indexPath.row
if color == colorSource[indexPath.row] {
cell.cellColorButton.layer.cornerRadius = 5.0
cell.cellColorButton.clipsToBounds = true
cell.cellColorButton.layer.borderWidth = 2
cell.cellColorButton.layer.borderColor = UIColor.black.cgColor
}
return cell
}
【问题讨论】:
-
永远不要只在我们必须提供其他的情况下才这样做。
标签: ios uicollectionview swift4 uicollectionviewcell