Alex Rivera | Logout

Page count of UICollectionView with paging in iOS

Asked 2012-11-17T18:24:55.463
9

Consider a UICollectionView with flow layout and paging enabled (by setting pagingEnabled to YES).

What would be the simplest way of obtaining the total number of pages?

And where would be the most appropriate place to update the total number of pages (given that it might change if items are added/deleted, the size of the collection view changes or the layout changes)?

Edit
Report

1 Answer

6

If the UICollectionView scrolls horizontally, you divide its contentSize's width to its frame's width:

int pages = floor(self.collectionView.contentSize.width /    
                  self.collectionView.frame.size.width) + 1;

If it scrolls vertically, you divide its contentSize's height to its frame's height:

int pages = floor(self.collectionView.contentSize.height /    
                  self.collectionView.frame.size.height) + 1;
answered 2012-12-07T11:52:02.940

Your Answer