gpt4 book ai didi

ios - 在 Collection View 中找到中间单元格并更改其内容

转载 作者:行者123 更新时间:2023-11-30 11:25:05 25 4
gpt4 key购买 nike

我的目标是在中间单元格中包含全文,在其他单元格中包含截断文本,但是随着中间单元格的更改,这种样式不应改变(意味着中间一个全文和其他单元格被截断)。

预设:在水平滚动 Collection View 中无限滚动,并在单元格中带有标签。

我有 3 个细胞,它们应该看起来像这样 [ 1D ]---[ 1 Day ]---[ 1D ]

最佳答案

您可以执行以下操作来查找中间单元格:

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

let center = self.view.convert(collectionView.center, to: collectionView)
let index = collectionView.indexPathForItem(at: center)

if (indexPath == index) {
// truncated text
} else {
// don't truncated text
}

return cell
}

关于ios - 在 Collection View 中找到中间单元格并更改其内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50832235/

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