Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import UIKit
  2.  
  3. class MarkSheetCollectionViewLayout: UICollectionViewLayout {
  4. //MARK: #1
  5. private enum Consts {
  6. static let rowHeaderWidth: CGFloat = 100
  7. static let oneRowHeight: CGFloat = 50
  8. static let columnHeaderHeight: CGFloat = 40
  9. }
  10. //MARK: #2
  11. private var numberOfColumns: Int {
  12. return collectionView!.numberOfItems(inSection: 0)
  13. }
  14. private var numberOfRows: Int {
  15. return collectionView!.numberOfSections
  16. }
  17. //MARK: #3
  18. private var columnWidth: CGFloat {
  19. let contentWidth = collectionViewContentSize.width - Consts.rowHeaderWidth
  20. return (contentWidth / CGFloat(numberOfColumns))
  21. }
  22. //MARK: #4
  23. override var collectionViewContentSize: CGSize {
  24. let contentHght = Consts.columnHeaderHeight + Consts.oneRowHeight * CGFloat(numberOfRows)
  25. return CGSize(width: collectionView?.bounds.width ?? 0, height: contentHght)
  26. }
  27. //MARK: #5
  28. override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
  29. return collectionView?.bounds.width != newBounds.width
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement