ViewController.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // ViewController.swift
  3. // app
  4. //
  5. // Created by Inigo Valentin on 28/09/16.
  6. // Copyright © 2016 Margolariak. All rights reserved.
  7. //
  8. import UIKit
  9. class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
  10. override func viewDidLoad() {
  11. super.viewDidLoad()
  12. // Do any additional setup after loading the view, typically from a nib.
  13. }
  14. override func didReceiveMemoryWarning() {
  15. super.didReceiveMemoryWarning()
  16. // Dispose of any resources that can be recreated.
  17. }
  18. let reuseIdentifier = "cell" // also enter this string as the cell identifier in the storyboard
  19. var items = ["Home", "Location", "La Blanca", "Actividades", "Blog", "Gallery"]
  20. // MARK: - UICollectionViewDataSource protocol
  21. // tell the collection view how many cells to make
  22. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  23. return self.items.count
  24. }
  25. // make a cell for each cell index path
  26. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  27. // get a reference to our storyboard cell
  28. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MenuCollectionViewCell
  29. // Use the outlet in our custom class to get a reference to the UILabel in the cell
  30. cell.myLabel.text = self.items[indexPath.item]
  31. cell.backgroundColor = UIColor.cyan // make cell more visible in our example project
  32. return cell
  33. }
  34. // MARK: - UICollectionViewDelegate protocol
  35. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  36. // handle tap events
  37. print("You selected cell #\(indexPath.item)!")
  38. }
  39. }