Skip to content

Instantly share code, notes, and snippets.

@YudhistherAryan
Last active August 1, 2021 15:01
Show Gist options
  • Save YudhistherAryan/e13ce125ff44bb17557bc5a0e9a5e0cf to your computer and use it in GitHub Desktop.
Save YudhistherAryan/e13ce125ff44bb17557bc5a0e9a5e0cf to your computer and use it in GitHub Desktop.
How to get the index of visible cell in the UICollectionView
//Put this function into the extension of the UICollectionVIewDelegate and you will get the index of the current cell displaying.
// This will be helpful when you will implemenet the image slider with the help of the collectionView(by default pagination of the collectionView).
func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
print("Currently visible cell is \(self.collectionView.indexPathsForVisibleItems)")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment