【问题标题】:Setting minimum line spacing in collectionView在 collectionView 中设置最小行距
【发布时间】:2014-10-14 08:38:25
【问题描述】:

我正在尝试在我的 collectionViewController 中使用 swift 设置最小行距,但我似乎找不到我需要使用的方法。我需要它以编程方式进行,因为我需要根据 selectedSegmentedIndex 动态更改它。如何以编程方式更改最小行距?

我尝试添加 UICollectionViewFlowLayout,但由于它是 UICollectionViewController,所以无法添加。

我想我需要使用类似的东西。

collectionView:layout:minimumLineSpacingForSectionAtIndex:

【问题讨论】:

    标签: ios iphone swift uicollectionview


    【解决方案1】:

    使您的UICollectionViewController 符合协议UICollectionViewDelegateFlowLayout

    你要找的方法是:

    - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section;

    【讨论】:

    • 我需要更改“行”的最小空间。
    • 是的 - 这个方法应该做到这一点。
    【解决方案2】:

    斯威夫特:

    func collectionView(collectionView: UICollectionView, layout
        collectionViewLayout: UICollectionViewLayout,
        minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
            return 1.0
    }
    

    【讨论】:

      【解决方案3】:

      Swift 4.2

        func collectionView(_ collectionView: UICollectionView, layout
              collectionViewLayout: UICollectionViewLayout,
                              minimumLineSpacingForSectionAt section: Int) -> CGFloat {
      
              return 10
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-27
        • 1970-01-01
        • 2022-01-14
        • 1970-01-01
        • 2019-06-22
        相关资源
        最近更新 更多