Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. import UIKit
  2.  
  3. class CalendarViewController: UIViewController {
  4.  
  5.  
  6. @IBOutlet weak var calendarCollectionView: UICollectionView!
  7.  
  8. override func viewDidLoad() {
  9. super.viewDidLoad()
  10. let layout = CalendarLayout()
  11. calendarCollectionView.collectionViewLayout = layout
  12.  
  13. // calendarCollectionView.register(HeaderView.classForCoder(), forCellWithReuseIdentifier: "HeaderView")
  14.  
  15. // Do any additional setup after loading the view.
  16. }
  17.  
  18. override func didReceiveMemoryWarning() {
  19. super.didReceiveMemoryWarning()
  20. // Dispose of any resources that can be recreated.
  21. }
  22.  
  23.  
  24. /*
  25. // MARK: - Navigation
  26.  
  27. // In a storyboard-based application, you will often want to do a little preparation before navigation
  28. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  29. // Get the new view controller using segue.destinationViewController.
  30. // Pass the selected object to the new view controller.
  31. }
  32. */
  33.  
  34. }
  35.  
  36. class CalendarLayout: UICollectionViewLayout {
  37. override var collectionViewContentSize: CGSize {
  38. return super.collectionViewContentSize
  39. }
  40.  
  41. override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
  42. return super.layoutAttributesForElements(in: rect)
  43. }
  44.  
  45. override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
  46. return super.layoutAttributesForItem(at: indexPath)
  47. }
  48.  
  49. override func layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
  50. return super.layoutAttributesForSupplementaryView(ofKind: elementKind, at: indexPath)
  51. }
  52.  
  53. override func layoutAttributesForDecorationView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
  54. return super.layoutAttributesForDecorationView(ofKind: elementKind, at: indexPath)
  55. }
  56.  
  57. override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
  58. return true
  59. }
  60. }
  61.  
  62.  
  63. extension CalendarViewController: UICollectionViewDataSource {
  64. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  65. return 5
  66. }
  67.  
  68. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  69. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CalendarEventCell", for: indexPath) as? CalendarEventCell ?? CalendarEventCell()
  70.  
  71. cell.titleLabel.text = "Title \(indexPath.row)"
  72.  
  73. return cell
  74. }
  75.  
  76. func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
  77. let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "HeaderView", for: indexPath) as? HeaderView ?? HeaderView()
  78.  
  79. headerView.titleLabel.text = "header title"
  80.  
  81. return headerView
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement