Last active
February 17, 2022 12:22
-
-
Save qubblr/f5d94dd0311d72dac5f1e75639b25f7b to your computer and use it in GitHub Desktop.
Method to get an index path for UICollectionView supplementary view
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
extension UICollectionView { | |
func indexPath(for supplementaryView: UICollectionReusableView?, ofKind kind: String = UICollectionView.elementKindSectionHeader) -> IndexPath? { | |
let elements = visibleSupplementaryViews(ofKind: kind) | |
let indexPaths = indexPathsForVisibleSupplementaryElements(ofKind: kind) | |
for (element, indexPath) in zip(elements, indexPaths) { | |
if element === supplementaryView { | |
return indexPath | |
} | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome! Thanks for saving my day 🙏