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