Search code examples
iosswiftuicollectionviewios13swift5

How do I set the collectionView position?


I have a UICollectionView build like in the picture. For example, I choose the 5th button and closed and opened the application. I want the 5th button to appear on the screen when the application is opened again. In other words, the UICollectionView should not return to the first position when the application is opened again.

https://i.hizliresim.com/mxX5qT.png


Solution

  • You can use this at your collection view's didSelectItem func :

    collectionView.scrollToItem(at: indexPath, at: .left, animated: true)
    

    Hope it helps...