|
|
@@ -11,6 +11,7 @@ import UIKit
|
|
|
class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
+ print("LOAD")
|
|
|
super.viewDidLoad()
|
|
|
// Do any additional setup after loading the view, typically from a nib.
|
|
|
}
|
|
|
@@ -20,25 +21,43 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
|
|
|
// Dispose of any resources that can be recreated.
|
|
|
}
|
|
|
|
|
|
- let reuseIdentifier = "cell" // also enter this string as the cell identifier in the storyboard
|
|
|
+ let reuseIdentifier = "cell"
|
|
|
+ var selected = 0
|
|
|
var items = ["Home", "Location", "La Blanca", "Actividades", "Blog", "Gallery"]
|
|
|
|
|
|
// MARK: - UICollectionViewDataSource protocol
|
|
|
|
|
|
- // tell the collection view how many cells to make
|
|
|
+ //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
|
|
|
+ //Make a cell for each section
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
|
|
|
- // get a reference to our storyboard cell
|
|
|
+ print("SET: \(selected)/\(indexPath.item)")
|
|
|
+
|
|
|
+ //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
|
|
|
+ //Make the updatable
|
|
|
+ //cell.setNeedsDisplay()
|
|
|
+ //cell.setNeedsLayout()
|
|
|
+
|
|
|
+ //Set text
|
|
|
+ cell.label.text = self.items[indexPath.item]
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //Mark the first cell as selected
|
|
|
+ if indexPath.item == selected{
|
|
|
+ cell.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
|
|
|
+ cell.label.font = UIFont.boldSystemFont(ofSize: cell.label.font.pointSize)
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ cell.bar.backgroundColor = UIColor(red: 148/255, green: 209/255, blue: 255/255, alpha: 1)
|
|
|
+ cell.label.font = UIFont.systemFont(ofSize: cell.label.font.pointSize)
|
|
|
+ }
|
|
|
|
|
|
return cell
|
|
|
}
|
|
|
@@ -46,7 +65,40 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
|
|
|
// MARK: - UICollectionViewDelegate protocol
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
- // handle tap events
|
|
|
+ // Return all labels to their original state, and mark the selected as such
|
|
|
+ var i = 0
|
|
|
+ selected = indexPath.item
|
|
|
+ for cell in collectionView.visibleCells as! [MenuCollectionViewCell]{
|
|
|
+ print("\(i)/\(indexPath.item)")
|
|
|
+ if i == indexPath.item{
|
|
|
+ print("CHANGE")
|
|
|
+ cell.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
|
|
|
+ cell.label.font = UIFont.boldSystemFont(ofSize: cell.label.font.pointSize)
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ cell.bar.backgroundColor = UIColor(red: 148/255, green: 209/255, blue: 255/255, alpha: 1)
|
|
|
+ cell.label.font = UIFont.systemFont(ofSize: cell.label.font.pointSize)
|
|
|
+
|
|
|
+ }
|
|
|
+ //cell.superview?.superview?.setNeedsDisplay()
|
|
|
+ //cell.setNeedsLayout()
|
|
|
+ //DispatchQueue.main.async{cell.setNeedsDisplay()}
|
|
|
+ i = i + 1
|
|
|
+ }
|
|
|
+ print("REDRAW")
|
|
|
+ //collectionView.setNeedsDisplay()
|
|
|
+ collectionView.layoutIfNeeded()
|
|
|
+ //collectionView.setNeedsLayout()
|
|
|
+ //DispatchQueue.main.async{collectionView.setNeedsDisplay()}
|
|
|
+ //dispatch_async(dispatch_get_main_queue(), {collectionView.setNeedsDisplay()})
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //Mark the selected one
|
|
|
+ //let sel = collectionView.visibleCells as! [[MenuCollectionViewCell]indexPath]
|
|
|
+
|
|
|
+
|
|
|
+ //let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MenuCollectionViewCell
|
|
|
print("You selected cell #\(indexPath.item)!")
|
|
|
}
|
|
|
|