【问题标题】:How to custom UICollectionView to left align in horizontal direction如何自定义 UICollectionView 在水平方向左对齐
【发布时间】:2021-08-13 22:55:37
【问题描述】:

任何人请指导我如何使 UICollectionView 成为

  1. 左对齐
  2. 将行数限制为 3

如下图所示(在热门列表中)

【问题讨论】:

    标签: ios swift uicollectionview


    【解决方案1】:

    您可以使用自定义 UICollectionViewLayout

    关键是通过自己计算手动布局元素

    这里有一个类似的example in github

    而且你需要重写以下两个方法

      override public func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {  }
      
    
      override public func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {   }
    

    【讨论】:

      【解决方案2】:

      找不到解决方案。所以我使用 Scrollview + StackView 制作了它。让生活再次快乐起来。 :)

      【讨论】:

        猜你喜欢
        • 2016-10-29
        • 2014-11-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-04
        • 1970-01-01
        • 2019-08-24
        • 1970-01-01
        相关资源
        最近更新 更多