Sheik_101 Sheik_101 - 2 months ago 9
iOS Question

How to scroll UICollectionView to the bottom programatically?

I have a

UICollectionView
. I want to scroll to the bottom when the view appears. How to do this?

Can someone help me out on this?.
Thanks in advance.

Answer

You can use the below code to scroll a UICollectionView programmatically to the bottom

NSInteger section = [self numberOfSectionsInCollectionView:collectionView] - 1;
NSInteger item = [self collectionView:collectionView numberOfItemsInSection:section] - 1;
NSIndexPath *lastIndexPath = [NSIndexPath indexPathForItem:item inSection:section];
[collectionView scrollToItemAtIndexPath:lastIndexPath atScrollPosition:UICollectionViewScrollPositionBottom animated:YES];
Comments