We have a collection view. I made a calendar that shows dates horizontally, and I scroll the dates horizontally. Now on the screen I see only 3-4 dates. Now I want it to automatically scroll to the specific date selected when the calendar screen was shown. So the date I want to scroll through is not yet displayed.
For this, I got the index path for a specific cell. Now I'm trying to scroll it to a specific index path.
func scrollCollectionView(indexpath:IndexPath) { // collectionView.scrollToItem(at: indexpath, at: .left, animated: true) //collectionView.selectItem(at: indexpath, animated: true, scrollPosition: .left) collectionView.scrollToItem(at: indexpath, at: .centeredHorizontally, animated: true) _ = collectionView.dequeueReusableCell(withReuseIdentifier: "DayCell", for: indexpath) as? DayCell }
Tell me how can I implement it?
source share