【发布时间】:2020-08-20 04:48:49
【问题描述】:
我为我的 horizontal UICollectionView 设置了部分。我希望每个部分第二行中的单元格项目是第一行中项目的两倍宽度。这是我设置的:
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 2
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if section == 0 {
return 2
}
return 1
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { //1.7, 2.7
if indexPath.row == 0 {
return CGSize(width: collectionView.frame.size.width/2,
height: collectionView.frame.size.height/2)
}
return CGSize(width: collectionView.frame.size.width,
height: collectionView.frame.size.height/2)
}
但这是最终结果:
我怎样才能摆脱较小尺寸物品中的空间并很好地布局它们?
注意:图片上的数字代表section和row(0 1 -> Section 0, Row 1)
这就是我想要实现的目标:
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewlayout uicollectionviewflowlayout