我有一个 Collection View ,其中单元格和行的最小间距设置为 10。单元格之间的水平间距调整正确,但我不知道如何更改单元格行之间的垂直间距。在它最初开发的 6 上,空间可以忽略不计并且工作正常。但在所有其他设备上,空间无缘无故地翻了两番。有什么方法可以将单元格行之间的间距设置为跨所有设备的恒定值吗?
最佳答案
目前还没有一种方法可以使用 AutoLayout 设置 Collection View 单元格的大小。我的猜测是您的单元格大小在其他屏幕尺寸上看起来不太好,因此您很可能需要实现 UICollectionViewDelegateFlowLayout
协议(protocol)(它扩展了 UICollectionViewDelegate
协议(protocol)) 和 func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
方法。
尽管如果情况并非如此,发布一些屏幕截图可能会有所帮助。
示例方法:
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
if(self.view.bounds.width > 400){
return CGSize(width:self.view.bounds.width/3-10, height:self.view.bounds.width/3-10)
}
return CGSize(width:self.view.bounds.width/2-10, height:self.view.bounds.width/2-10)
}
关于ios - UICollectionView 行间距在某些设备上变得很大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31567302/