swift - 调整 CollectionView 的单元格大小
问题描述
我需要制作类似技能页面的东西,所以我使用了集合视图,但我需要根据用户添加的技能来调整销售的宽度。我只需要如何调整单元格的大小
解决方案
您可以实现UICollectionViewDelegateFlowLayout
协议并使用该collectionView:layout:sizeForItemAtIndexPath:
方法。
例子:
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
let cellData = self.data[indexPath.item]
let skills = cellData.skills // Or fetch the skills from somewhere else
let width = skills.count * 100
let height = 100
return CGSize(width: width, height: height)
}
推荐阅读
- c# - 在 UWP 应用程序中打开和读取 Excel 文件
- botframework - Microsoft 聊天机器人显示 403 Quota Exceeded 错误
- nltk - NLTK 文本分类置信度朴素贝叶斯
- c - 使用英特尔 MKL 计算 `trans(a)*inv(b)*a` 的正确方法
- reactjs - 用于向下钻取表的反应库
- html - 如何制作不规则的div边框
- java - 从 IntelliJ Ultimate 2018.2.5 访问 MySQL 服务器
- java - 如何在更多 Apache POI Pivot 之间共享 Pivot Cache?
- python - 如何在 google colab 上升级 pandas
- python - 在 tensorflow 中使用 tf.data.Dataset api 恢复模型后在开发数据集上运行模型