Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class MarkSheetCollectionViewLayout: UICollectionViewLayout {
- //MARK: #1
- private enum Consts {
- static let rowHeaderWidth: CGFloat = 100
- static let oneRowHeight: CGFloat = 50
- static let columnHeaderHeight: CGFloat = 40
- }
- //MARK: #2
- private var numberOfColumns: Int {
- return collectionView!.numberOfItems(inSection: 0)
- }
- private var numberOfRows: Int {
- return collectionView!.numberOfSections
- }
- //MARK: #3
- private var columnWidth: CGFloat {
- let contentWidth = collectionViewContentSize.width - Consts.rowHeaderWidth
- return (contentWidth / CGFloat(numberOfColumns))
- }
- //MARK: #4
- override var collectionViewContentSize: CGSize {
- let contentHght = Consts.columnHeaderHeight + Consts.oneRowHeight * CGFloat(numberOfRows)
- return CGSize(width: collectionView?.bounds.width ?? 0, height: contentHght)
- }
- //MARK: #5
- override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
- return collectionView?.bounds.width != newBounds.width
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement