Created
February 25, 2020 10:47
-
-
Save MickaelCruzDB/8bcd0c4c7bd29206f0dac6b2af2ad711 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
// Working with functions categories collection view | |
if collectionView == self.functionsCategoriesCollectionView { | |
let cellFunctionsCategories = collectionView.dequeueReusableCell(withReuseIdentifier: "cellCat", for: indexPath) as! DevicePageFunctionsCategoriesCVCell | |
cellFunctionsCategories.cellTitleContent.text = ICDatabase.objects(FunctionCategory.self)[indexPath.row].name.uppercased() | |
cellFunctionsCategories.setGradientBorder(width: 10, colors: [UIColor(red: 127.0/255.0, green: 127.0/255.0, blue: 127.0/255.0, alpha: 1.0), UIColor(red: 47.0/255.0, green: 47.0/255.0, blue: 47.0/255.0, alpha: 1.0)]) | |
if indexPath == cellSelectionIndexPath { | |
if let cellToDeselect = collectionView.cellForItem(at: self.cellSelectionIndexPath) as? DevicePageFunctionsCategoriesCVCell { | |
cellToDeselect.cellView.addGradiant(colors: [UIColor.clear.cgColor, UIColor.clear.cgColor], angle: 0) | |
// Get all functions | |
self.filtered = GlobalVariables.currentProduct.functions.filter { _ in | |
return true | |
} | |
self.functionsCollectionView.reloadData() | |
} | |
} | |
return cellFunctionsCategories | |
} | |
} | |
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
// Working with functions categories collection view | |
if collectionView == self.functionsCategoriesCollectionView { | |
let cell = collectionView.cellForItem(at: indexPath) as! DevicePageFunctionsCategoriesCVCell | |
cell.isHidden = false | |
cell.cellView.isHidden = false | |
cell.isSelected = true | |
cell.cellView.clipsToBounds = true | |
cell.cellView.layer.cornerRadius = 25 | |
cell.cellView.addGradiant(colors: [UIColor(red: 127.0/255.0, green: 127.0/255.0, blue: 127.0/255.0, alpha: 1.0).cgColor, UIColor(red: 47.0/255.0, green: 47.0/255.0, blue: 47.0/255.0, alpha: 1.0).cgColor], angle: 45) | |
if cellSelectionIndexPath == indexPath { | |
// it was already selected | |
cellSelectionIndexPath = nil | |
collectionView.deselectItem(at: indexPath, animated: true) | |
cell.cellView.addGradiant(colors: [UIColor.clear.cgColor, UIColor.clear.cgColor], angle: 0) | |
self.filtered = GlobalVariables.currentProduct.functions.filter { _ in | |
return true | |
} | |
self.functionsCollectionView.reloadData() | |
} else { | |
// wasn't yet selected, so let's remember it | |
cellSelectionIndexPath = indexPath | |
// Filter with seletec category name | |
let cellCategoryName = ICDatabase.objects(FunctionCategory.self)[indexPath.row] | |
self.filtered = GlobalVariables.currentProduct.functions.filter { function in | |
return function.functionCategory.contains(cellCategoryName) | |
} | |
self.functionsCollectionView.reloadData() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have exactly the same problem with :