Page count of UICollectionView with paging in iOS

后端 未结 2 1686
野性不改
野性不改 2020-12-16 20:47

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

What would be the simplest

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 21:06

    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;
    

提交回复
热议问题