我有一个集合视图,单元格和线条的最小间距设置为10。单元格之间的水平间距可以正确调整,但我不知道如何改变单元格行之间的垂直间距。在最初开发它的6上,空间可以忽略不计,工作正常。但在其他所有设备上,空间的大小都是四倍,没有明显的原因。有没有办法在所有设备上将单元格行之间的间距设置为常量值?
发布于 2015-07-22 23:30:59
目前还没有一种方法可以使用AutoLayout设置集合视图单元格的大小。我的猜测是,您的单元格的大小在其他屏幕尺寸上看起来并不理想,因此您很可能需要实现UICollectionViewDelegateFlowLayout协议(它扩展了UICollectionViewDelegate协议)和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)
}https://stackoverflow.com/questions/31567302
复制相似问题