如何创建一个集合视图,在该集合视图中,我们可以将卡片视图类型中的第一个单元格和最后一个单元格显示为填充行,而其他单元格显示为一行中的两个项目。 如何以编程方式实现它们?
请建议我做一下这个工作的想法
任务
使其显示为4行,即屏幕的第1项全宽和 最后一个
尽可能帮助代码
答案 0 :(得分:1)
检查sizeForItemAtIndexPath
内收集单元格的第一行和最后一行/项目,并给出相应的大小
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
if indexPath.row == 0 || indexPath.row == dataArray.count - 1 {
return CGSizeMake(fullWidth, height) // for 1st and last item/cell
}else{
return CGSizeMake(halfWidth, height) //for all items/cells
}
}
获取屏幕宽度:
let screenSize: CGRect = UIScreen.mainScreen().bounds
let screenWidth = screenSize.width