0
我需要確定uicollectionview的高度。如何在swift中統計uicollectionview的行數
let layout = contactCollectionView.collectionViewLayout
let heightSize = String(Int(layout.collectionViewContentSize.height))
上述解決方案適用於我的項目中的一些情況。在這種特定的情況下,我需要對行數進行計數,然後將其與一個數字相乘以找到高度。
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// height = (count rows) * 30 . every cell height is 30
// every cell has different width.
return (presenter?.selectedContact.count)!
}
如何查找行數?
更新
這是我的收藏查看。每個單元格都有不同的寬度(因爲它是字符串)。所以它有不同的行。這個的CollectionView的寬度view.frame
你的意思是你要查找的滾動高度?像整個內容的大小? – LinusGeffarth
layout.collectionViewContentSize.height在這種情況下返回零。因爲我的stackView的高度爲零,並且無法計算高度。我需要計算數字行數,然後用數字計算多個數字以查找整個內容大小。 –
所以你想知道返回30後它會*的高度,對吧? – LinusGeffarth