Advertisement
Guest User

Untitled

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