https://github.com/akxo/paging-collection-view-layout
custom collection view layout that allows you to page by cell, not screen
https://github.com/akxo/paging-collection-view-layout
carousel cell cocoapod collectionview collectionviewflowlayout collectionviewlayout paging swift
Last synced: 6 months ago
JSON representation
custom collection view layout that allows you to page by cell, not screen
- Host: GitHub
- URL: https://github.com/akxo/paging-collection-view-layout
- Owner: akxo
- License: mit
- Created: 2019-08-09T21:09:54.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-11T13:44:13.000Z (about 5 years ago)
- Last Synced: 2024-12-07T14:51:08.460Z (6 months ago)
- Topics: carousel, cell, cocoapod, collectionview, collectionviewflowlayout, collectionviewlayout, paging, swift
- Language: Swift
- Size: 3.56 MB
- Stars: 182
- Watchers: 3
- Forks: 23
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# paging-collection-view-layout
custom collection view layout that allows you to page by cell, not screen
## installation
### cocoapods
use [cocoapods](http://cocoapods.org/) to install `PagingCollectionViewLayout` by adding it to your `Podfile`:```ruby
platform :ios, '9.0'
use_frameworks!
pod 'PagingCollectionViewLayout'
`````` swift
import PagingCollectionViewLayout
```
### manual
add `PagingCollectionViewLayout.swift` to your project
## usageinstantiate a layout property
```swift
let layout = PagingCollectionViewLayout()
```
set the following properties
```swift
layout.itemSize =
layout.minimumLineSpacing =
layout.scrollDirection = .horizontal
```
instantiate a collection view using the layout property
```swift
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
```
for snappy scrolling set the following
```swift
collectionView.decelerationRate = .fast
```#### note:
~~collectionView.isPagingEnabled = true~~
## optional customization
### vertical scrolling

```swift
layout.scrollDirection = .vertical
```
or since the default is vertical~~layout.scrollDirection = .horizontal~~
### section spacing
- center the item in focus
- allow the previous item to be visible
set the following property
```swift
layout.sectionInset =
```
- **horizontal collection view -** set left and right insets
- **vertical collection view -** set top and bottom insets### skipping items

`layout.velocityThresholdPerPage` determines the velocity needed to skip an item (default = 2.0)
- a non zero swipe velocity will result in the collection view scrolling to the prev/next item
- the number of items skipped = swipe velocity / velocityThresholdPerPage### multiple items per page

```swift
layout.numberOfItemsPerPage = 2
```