在 Collection 视图中,第一个和最后一个卡片视图要在宽屏中填充
In Collection view in which 1st and last card view to be filled in wide screen
如何创建一个集合视图,在该集合视图中,我们可以使卡片视图类型中集合的第一个单元格和最后一个单元格显示为填充在行中,而介于两者之间的其他单元格则显示为一行中的两个项目。
如何以编程方式实现它们?
请给我一个想法来完成这项工作
任务
- 创建 6 个项目的集合视图
让它显示在 4 行中,即第一个项目全屏宽度和
最后一个也是
如果可能,请帮助编写代码
检查 sizeForItemAtIndexPath
内收集单元格的第一个和最后一个 row/item 并给出相应的大小
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
如何创建一个集合视图,在该集合视图中,我们可以使卡片视图类型中集合的第一个单元格和最后一个单元格显示为填充在行中,而介于两者之间的其他单元格则显示为一行中的两个项目。 如何以编程方式实现它们?
请给我一个想法来完成这项工作
任务
- 创建 6 个项目的集合视图
让它显示在 4 行中,即第一个项目全屏宽度和 最后一个也是
如果可能,请帮助编写代码
检查 sizeForItemAtIndexPath
内收集单元格的第一个和最后一个 row/item 并给出相应的大小
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