Made the code more concise
This commit is contained in:
parent
f4fa6d8291
commit
cd23384db3
@ -5,30 +5,21 @@
|
|||||||
// Created by Dhamodaram Nandi on 05/06/20.
|
// Created by Dhamodaram Nandi on 05/06/20.
|
||||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||||
//
|
//
|
||||||
|
// Left aligns items and makes the minimumInteritemSpacing absolute.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class UICollectionViewLeftAlignedLayout: UICollectionViewFlowLayout {
|
class UICollectionViewLeftAlignedLayout: UICollectionViewFlowLayout {
|
||||||
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
|
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
|
||||||
guard let attributes = super.layoutAttributesForElements(in: rect) else {
|
guard let attributes = super.layoutAttributesForElements(in: rect) else { return nil }
|
||||||
return nil
|
|
||||||
}
|
|
||||||
var newAttributesForElementsInRect = [UICollectionViewLayoutAttributes]()
|
var newAttributesForElementsInRect = [UICollectionViewLayoutAttributes]()
|
||||||
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 attribute.frame.origin.y >= maxY {
|
if let previousFrame = newAttributesForElementsInRect.last,
|
||||||
leftMargin = leftPadding
|
MVMCoreGetterUtility.cgfequal(previousFrame.frame.minY, attribute.frame.minY) {
|
||||||
|
attribute.frame.origin.x = previousFrame.frame.maxX + minimumInteritemSpacing
|
||||||
} else {
|
} else {
|
||||||
var newLeftAlignedFrame = attribute.frame
|
attribute.frame.origin.x = 0
|
||||||
newLeftAlignedFrame.origin.x = leftMargin
|
|
||||||
attribute.frame = newLeftAlignedFrame
|
|
||||||
}
|
}
|
||||||
attribute.frame.origin.x = leftMargin
|
|
||||||
leftMargin += attribute.frame.width + interItemSpacing
|
|
||||||
maxY = max(attribute.frame.maxY, maxY)
|
|
||||||
newAttributesForElementsInRect.append(attribute)
|
newAttributesForElementsInRect.append(attribute)
|
||||||
}
|
}
|
||||||
return newAttributesForElementsInRect
|
return newAttributesForElementsInRect
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user