| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // ViewController.swift
- // app
- //
- // Created by Inigo Valentin on 28/09/16.
- // Copyright © 2016 Margolariak. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
-
- let reuseIdentifier = "cell" // also enter this string as the cell identifier in the storyboard
- var items = ["Home", "Location", "La Blanca", "Actividades", "Blog", "Gallery"]
-
-
- // MARK: - UICollectionViewDataSource protocol
-
- // tell the collection view how many cells to make
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return self.items.count
- }
-
- // make a cell for each cell index path
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-
- // get a reference to our storyboard cell
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MenuCollectionViewCell
-
- // Use the outlet in our custom class to get a reference to the UILabel in the cell
- cell.myLabel.text = self.items[indexPath.item]
- cell.backgroundColor = UIColor.cyan // make cell more visible in our example project
-
- return cell
- }
-
- // MARK: - UICollectionViewDelegate protocol
-
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- // handle tap events
- print("You selected cell #\(indexPath.item)!")
- }
- }
|