0
我自定義集合視圖單元格的大小。如何使單元格適合集合視圖
如果我有1或2個單元格,它可以很好地工作,但是當我有3個單元格時,它不能很好地工作。
這裏是我的情況下,代碼我有3個單元:
case 3:
let lastPhoto = info.albumOtherPhoto.photos.first
let lastPhotoWidth = lastPhoto?.width
let lastPhotoHeight = lastPhoto?.height
var sizeForFistPhoto : CGSize!
var sizeForOtherPhotos: CGSize!
if lastPhotoWidth > lastPhotoHeight {
sizeForFistPhoto = CGSizeMake(screenWidth, screenWidth * 0.5)
sizeForOtherPhotos = CGSizeMake(screenWidth * 0.5, screenWidth * 0.5)
} else {
sizeForFistPhoto = CGSizeMake(screenWidth * 0.5, screenWidth)
sizeForOtherPhotos = CGSizeMake(screenWidth * 0.5, screenWidth * 0.5)
}
self.sizes.append(sizeForFistPhoto)
self.sizes.append(sizeForOtherPhotos)
self.sizes.append(sizeForOtherPhotos)
和CollectionViewDelegateFlowLayout:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return self.sizes[indexPath.row]
}
我的代碼的結果是:
但我希望它顯示如下:
是否有可能實現這一目標代碼像我一樣(因爲我能實現這個接口生成器)?
固定它是否計劃將有更多的細胞或僅有3?如果是這樣,你應該繼承你的佈局類 –
更多的單元格,最大值是6,我只測試1,2,3單元格:)。 – Khuong
您如何期望它具有更多細胞? –