Przeglądaj źródła

First tab sleected by default.

Iñigo Valentin 9 lat temu
rodzic
commit
4a7cf9e9f4
2 zmienionych plików z 12 dodań i 28 usunięć
  1. 3 15
      MenuCollectionViewCell.swift
  2. 9 13
      app/ViewController.swift

+ 3 - 15
MenuCollectionViewCell.swift

@@ -20,8 +20,6 @@
 
 import UIKit
 
-private let highlightedColor = UIColor(rgb: 0xD8D8D8)
-
 /**
  Extension of UICollectionViewCell for the main menu.
  */
@@ -31,25 +29,21 @@ class MenuCollectionViewCell: UICollectionViewCell {
  
 	@IBOutlet weak var bar: UIView!
 	
-	var shouldTintBackgroundWhenSelected = true // You can change default value
-	var specialHighlightedArea: UIView?
 	
-	override var isHighlighted: Bool { // make lightgray background show immediately
+	override var isHighlighted: Bool {
 		willSet {
 			onSelected(newValue)
 		}
 	}
-	override var isSelected: Bool { // keep lightGray background until unselected
+	override var isSelected: Bool {
 		willSet {
 			onSelected(newValue)
 		}
 	}
 	func onSelected(_ newValue: Bool) {
-		//self.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
-		//self.label.font = UIFont.boldSystemFont(ofSize: self.label.font.pointSize)
+
 		guard selectedBackgroundView == nil else { return }
 		if newValue == true {
-			//contentView.backgroundColor = newValue ? highlightedColor : UIColor.clear
 			self.bar.backgroundColor = UIColor(red: 148/255, green: 209/255, blue: 255/255, alpha: 1)
 			self.label.font = UIFont.boldSystemFont(ofSize: self.label.font.pointSize)
 			self.label.textColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1)
@@ -61,9 +55,3 @@ class MenuCollectionViewCell: UICollectionViewCell {
 		}
 	}
 }
-
-extension UIColor {
-	convenience init(rgb: Int, alpha: CGFloat = 1.0) {
-		self.init(red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0, green: CGFloat((rgb & 0xFF00) >> 8) / 255.0, blue: CGFloat(rgb & 0xFF) / 255.0, alpha: alpha)
-	}
-}

+ 9 - 13
app/ViewController.swift

@@ -247,6 +247,8 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 		self.delegate = UIApplication.shared.delegate as? AppDelegate
 		self.delegate?.controller = self
 		
+		//self.sectionCollection.visibleCells[0].isSelected = true
+		
 		super.viewDidLoad()
 		
 	}
@@ -339,26 +341,20 @@ class ViewController: UIViewController, UICollectionViewDataSource, UICollection
 	
 	//Make a cell for each section
 	func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-				
+		
+		var first = true
+		
 		//Get a reference to our storyboard cell
 		let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MenuCollectionViewCell
 		
 		//Set text
 		cell.label.text = self.items[indexPath.item]
 		
-		//Mark the first cell as selected...
-		/*if indexPath.item == selected{
-			cell.bar.backgroundColor = UIColor(red: 148/255, green: 209/255, blue: 255/255, alpha: 1)
-			cell.label.font = UIFont.boldSystemFont(ofSize: cell.label.font.pointSize)
-			cell.label.textColor = UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1)
+		// Mark the first one as selected.
+		if indexPath.item == 0{
+			cell.isSelected = true
+			first = false
 		}
-			
-		//... and the others as unselected
-		else{
-			cell.bar.backgroundColor = UIColor(red: 90/255, green: 180/255, blue: 255/255, alpha: 1)
-			cell.label.font = UIFont.systemFont(ofSize: cell.label.font.pointSize)
-			cell.label.textColor = UIColor(red: 200/255, green: 200/255, blue: 200/255, alpha: 1)
-		}*/
 		
 		return cell
 	}