ios - 如何减少 collectionview 中两个单元格之间的垂直空间?

标签 ios swift uicollectionview

enter image description here

如何减少collectionview中两个单元格之间的垂直间距?

最佳答案

在创建 Collection View 布局时添加这些行

layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 0

 let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
        layout.sectionInset = UIEdgeInsets(top: 20, left: 0, bottom: 10, right: 0)
        layout.itemSize = CGSize(width: screenWidth/2, height: screenWidth/2)
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        collectionView!.collectionViewLayout = layout

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    if indexPath.row == 0
    {
        return CGSize(width: screenWidth, height: screenWidth/2)
    }
    return CGSize(width: screenWidth/2, height: screenWidth/2);

}

关于ios - 如何减少 collectionview 中两个单元格之间的垂直空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47709215/

相关文章:

ios - 使用 OutputStream 写入时如何检查是否成功?

iOS:本地化独立于 iPad 语言设置的应用程序

ios - UIAlertView 未从辅助类中显示

ios - 在 Swift 中批量创建变量

ios - 仅 iPhone 6 模拟器像素颜色错误

ios - 如何在collectionview中添加类似pickerview的声音反馈?

iOS:防止 Restkit 对 URL 编码逗号

ios - 将 UICollectionView 触摸事件传递给其父 UITableViewCell

ios - 如何以编程方式启用/禁用 UICollectionView 中的节标题?

swift - 如何从 Swift 5 中的 MLModel(机器学习模型)获得预测的置信度