layout changes updated
This commit is contained in:
parent
2ec4881be6
commit
f4fa6d8291
@ -61,6 +61,7 @@ open class Tags: View, MFButtonProtocol {
|
|||||||
let layout = UICollectionViewLeftAlignedLayout()
|
let layout = UICollectionViewLeftAlignedLayout()
|
||||||
layout.estimatedItemSize = CGSize(width: 140, height: 40)
|
layout.estimatedItemSize = CGSize(width: 140, height: 40)
|
||||||
layout.minimumLineSpacing = 24.0
|
layout.minimumLineSpacing = 24.0
|
||||||
|
layout.minimumInteritemSpacing = 12.0
|
||||||
return layout
|
return layout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,39 +13,24 @@ class UICollectionViewLeftAlignedLayout: UICollectionViewFlowLayout {
|
|||||||
guard let attributes = super.layoutAttributesForElements(in: rect) else {
|
guard let attributes = super.layoutAttributesForElements(in: rect) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var rows = [Row]()
|
var newAttributesForElementsInRect = [UICollectionViewLayoutAttributes]()
|
||||||
var currentRowY: CGFloat = -1
|
var leftMargin: CGFloat = 0.0;
|
||||||
|
let leftPadding: CGFloat = 0
|
||||||
|
let interItemSpacing = minimumInteritemSpacing
|
||||||
|
var maxY: CGFloat = -1.0
|
||||||
for attribute in attributes {
|
for attribute in attributes {
|
||||||
if currentRowY != attribute.frame.origin.y {
|
if attribute.frame.origin.y >= maxY {
|
||||||
currentRowY = attribute.frame.origin.y
|
leftMargin = leftPadding
|
||||||
rows.append(Row(spacing: 10))
|
} else {
|
||||||
|
var newLeftAlignedFrame = attribute.frame
|
||||||
|
newLeftAlignedFrame.origin.x = leftMargin
|
||||||
|
attribute.frame = newLeftAlignedFrame
|
||||||
}
|
}
|
||||||
rows.last?.add(attribute: attribute)
|
attribute.frame.origin.x = leftMargin
|
||||||
}
|
leftMargin += attribute.frame.width + interItemSpacing
|
||||||
rows.forEach { $0.tagLayout(collectionViewWidth: collectionView?.frame.width ?? 0) }
|
maxY = max(attribute.frame.maxY, maxY)
|
||||||
return rows.flatMap { $0.attributes }
|
newAttributesForElementsInRect.append(attribute)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Row {
|
|
||||||
|
|
||||||
var attributes = [UICollectionViewLayoutAttributes]()
|
|
||||||
var spacing: CGFloat = 0
|
|
||||||
|
|
||||||
init(spacing: CGFloat) {
|
|
||||||
self.spacing = spacing
|
|
||||||
}
|
|
||||||
|
|
||||||
func add(attribute: UICollectionViewLayoutAttributes) {
|
|
||||||
attributes.append(attribute)
|
|
||||||
}
|
|
||||||
|
|
||||||
func tagLayout(collectionViewWidth: CGFloat) {
|
|
||||||
let padding = 8
|
|
||||||
var offset = padding
|
|
||||||
for attribute in attributes {
|
|
||||||
attribute.frame.origin.x = CGFloat(offset)
|
|
||||||
offset += Int(attribute.frame.width + spacing)
|
|
||||||
}
|
}
|
||||||
|
return newAttributesForElementsInRect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user