ios - 使用带有 FlowLayout 的 UICollectionView 的标签组件?

标签 ios uicollectionview uicollectionviewlayout

我想做的是在没有空间的情况下将每个 View 放在下一行。标签库正在使用的相同原则(这么认为)。我不希望他们滚动只是为了在下一行并左对齐。这是我的代码:

self.collection.register(UINib(nibName: "FlowCell", bundle: nil), forCellWithReuseIdentifier: "tag")
    self.collection.showsHorizontalScrollIndicator = false
    self.collection.showsVerticalScrollIndicator = false
    self.collection.dataSource = self
    self.collection.delegate = self
    let layout = collection.collectionViewLayout as! UICollectionViewFlowLayout
    layout.estimatedItemSize = CGSize(width: 10, height: 18)

这就是结果

  1. 具有水平滚动方向。这里我只有一行:

enter image description here

  1. 具有垂直滚动方向。这里的内容居中:

enter image description here

这就是我想要完成的:

enter image description here

当然,最后一张图像上的项目内容不同,但如果标签在同一行上不能有多个,我希望项目左对齐。

最佳答案

你应该尝试这个:

https://github.com/mokagio/UICollectionViewLeftAlignedLayout

看起来正是您想要的。

关于ios - 使用带有 FlowLayout 的 UICollectionView 的标签组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42410077/

相关文章:

ios - 关于 iOS 13 更新

ios - UICollectionViewLayout 子类中未调用 layoutAttributesClass

ios - DiffableDataSource:快照不会重新加载页眉和页脚

ios - 每周自动更新标签

ios - Unity3d Ios 应用程序的 Keen.io 实现

ios安装mobileconfig卡住白屏

ios - 在 uitableviewcell 中使用 uicollectionview

ios - CollectionView 方法 'referenceSizeForHeaderInSection' 引发异常

ios - 未调用 UICollectionReusableView 方法

ios - 根据 uiLabel 文本更改水平 Collection View 宽度