使用带有 FlowLayout 的 UICollectionView 的标签组件?
Tags component using UICollectionView with FlowLayout?
我想做的是,如果没有 space,则将每个视图都放在下一行。标签库正在使用的相同原则(这么认为)。我不希望他们滚动只是为了在下一行并左对齐。这是我的代码:
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)
这是结果
- 水平滚动方向。这里我只有一行:
- 垂直滚动方向。这里的内容居中:
这就是我要实现的目标:
当然,最后一张图片上的项目内容不同,但如果同一行上的标签不能超过一个,我希望项目保持对齐。
你应该试试这个:
https://github.com/mokagio/UICollectionViewLeftAlignedLayout
看起来正是您想要的。
我想做的是,如果没有 space,则将每个视图都放在下一行。标签库正在使用的相同原则(这么认为)。我不希望他们滚动只是为了在下一行并左对齐。这是我的代码:
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)
这是结果
- 水平滚动方向。这里我只有一行:
- 垂直滚动方向。这里的内容居中:
这就是我要实现的目标:
当然,最后一张图片上的项目内容不同,但如果同一行上的标签不能超过一个,我希望项目保持对齐。
你应该试试这个:
https://github.com/mokagio/UICollectionViewLeftAlignedLayout
看起来正是您想要的。