31 lines
1.2 KiB
Swift
31 lines
1.2 KiB
Swift
//
|
|
// TableFlowLayout.swift
|
|
// VDS
|
|
//
|
|
// Created by Nadigadda, Sumanth on 02/05/24.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
final class MatrixFlowLayout : UICollectionViewFlowLayout {
|
|
|
|
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
|
|
guard let layoutAttributesObjects = super.layoutAttributesForElements(in: rect) else { return nil }
|
|
layoutAttributesObjects.forEach({ layoutAttributes in
|
|
if layoutAttributes.representedElementCategory == .cell,
|
|
let newFrame = layoutAttributesForItem(at: layoutAttributes.indexPath)?.frame {
|
|
layoutAttributes.frame = newFrame
|
|
}
|
|
})
|
|
return layoutAttributesObjects
|
|
}
|
|
|
|
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
|
|
guard let collectionView = collectionView,
|
|
let layoutAttributes = super.layoutAttributesForItem(at: indexPath) else { return nil }
|
|
let itemsCount = CGFloat(collectionView.numberOfItems(inSection: indexPath.section))
|
|
layoutAttributes.frame.size.width = ceil(collectionView.safeAreaLayoutGuide.layoutFrame.width / itemsCount)
|
|
return layoutAttributes
|
|
}
|
|
}
|