ios - 在集合视图中找到中间单元格并更改其内容
问题描述
我的目标是在中间单元格中有全文,在其他单元格中截断文本,但是随着中间单元格的变化,这种样式不应该改变(意味着中间的一个全文和其他的被截断)。
预设:在水平滚动的集合视图中无限滚动,单元格中有标签。
我有 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
}
推荐阅读
- go - 在实例生成期间修改结构字段
- excel - 如何在EXCEL中的每日数据中选择选定月份的最后一天
- java-8 - 如何在 Java8 中将 Current Date 更改为 MinguoDate?
- angularjs - 命名空间未定义打字稿 - 角度
- java - 没有活动的runOnUiThread
- c# - 无法使用 log4javascript 将客户端日志发送到服务器(Asp.net Web API)
- continuous-deployment - 无人机 ci 发布生成的乳胶 pdf
- android - Android Flutter ABI 架构回退
- mysql - 选择实体包含列表的位置哪些元素具有另一个列表
- css - 当容器和子项具有自动宽度时如何添加水平滚动条?