我的目标是在中间单元格中使用完整文本,在其他单元格中使用截断文本,但是如果更改中间单元格,则此样式不应更改(表示中间一个全文而其他单词被截断)。
预设:水平滚动集合视图中的无限滚动,单元格中带有标签。
我有3个细胞,他们应该看起来像这样[1D] --- [1天] --- [1D]
答案 0 :(得分:0)
你可以做这样的事情来找到中间单元格:
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
}