[英]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.