gpt4 book ai didi

ios - 如何突出显示选定的 UICollectionView 单元格? ( swift )

转载 作者:IT王子 更新时间:2023-10-29 05:11:39 26 4
gpt4 key购买 nike

我有一个 UICollectionView,用户可以选择多个单元格。跟踪哪些单元格已被选中有点困难,因此我需要一些方法来在单元格被点击时突出显示/创建边框。

代码:

func collectionView(collectionView: UICollectionView, shouldSelectItemAtIndexPath indexPath: NSIndexPath) -> Bool {

addToList.append(objectsArray[indexPath.row])

return true

}

最佳答案

您可以在 didSelectItemAtIndexPath 上使用边框更改覆盖事件,如下面的代码并在单元格上分配新设置。

swift 3.x:

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
addToList.append(objectsArray[indexPath.row])
let cell = collectionView.cellForItem(at: indexPath)
cell?.layer.borderWidth = 2.0
cell?.layer.borderColor = UIColor.gray.cgColor
}

关于ios - 如何突出显示选定的 UICollectionView 单元格? ( swift ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30598664/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com