[英]Collection view cell layout
大家好,我正在尝试创建一个类似于AirBnB应用的水平滚动。 到目前为止,一切都进展顺利,但我遇到了一些问题。 我尝试使每第三个项目变大。 不知为何不调整大小。 见下面的截图
第三项没有任何内容,但没有调整大小。 达到最大高度 相反,它弄乱了整个布局。
应该是
这是我的工作
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
if indexPath.item % 3 == 0 && indexPath.item != 0 {
return CGSizeMake(420, 520)
}
return CGSizeMake(420, 260)
}
我在这里做错了什么?
单元格大小由UICollectionViewDelegateFlowLayout方法设置
optional func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
例如:
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize{
if indexPath.item % 3 == 0 && indexPath.item != 0 {
return CGSize(400,1200)
}
return CGSize(400,600)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.