SnappingLayout enables a snap behaviour for UICollectionViews
.
It works with horizontal scrolling and there are 3 different types: left, center and right.
You can scroll your collection view and it will automatically snap to the chosen position after decelerating.
The snap supports all kinds of collection view configurations: with sectionInset
, minimumLineSpacing
, contentInset
and so forth.
- ๐ฅ Requirements
- ๐ป Installation
- ๐ Example Project
- ๐ Usage
- ๐จโ๐ป Authors
- ๐ฌ Contributing
- ๐ฎ License
- iOS 9.0+
- Swift 4.2+
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate SnappingLayout into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'SnappingLayout'
Then, run the following command:
$ pod install
only available from version
0.1.2
onwards
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate SnappingLayout into your Xcode project using Carthage, specify it in your Cartfile:
github "SnappingLayout" ~> 0.1.2
Run carthage update to build the framework and drag the built SnappingLayout.framework into your Xcode project.
only available from version
0.1.4
onwards
Swift Package Manager is a tool for managing the distribution of Swift code. Itโs integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
To integrate SnappingLayout into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:
dependencies: [
.package(url: "https://github.com/getmimo/SnappingLayout.git", .upToNextMajor(from: "0.1.4"))
]
If you prefer not to use either of the aforementioned dependency managers, you can always rely on the good old way of integrating SnappingLayout into your project manually.
To run the example project, clone the repo, and run pod install from the Example directory first. Open SnappingPresentationViewController to see the code needed to implement the snapping.
Just use SnappingLayout as a replacement for the traditional UICollectionViewFlowLayout.
It's as simple as:
- Importing it:
import SnappingLayout
- Instantiating it:
let snappingLayout = SnappingLayout()
- And using it:
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: snappingLayout)
- Set the deceleration rate of the collection view to fast:
collectionView.decelerationRate = .fast
There are three types of snappingLayout
: left, center and right.
This is the default value when a new instance of snappingLayout
is created and it will snap the position of the cell to the left side of the collection view.
let snappingLayout = SnappingLayout()
snappingLayout.snapPosition = .left
This will snap the position of the cell to the center of the collection view.
let snappingLayout = SnappingLayout()
snappingLayout.snapPosition = .center
This will snap the position of the cell to the right of the collection view.
let snappingLayout = SnappingLayout()
snappingLayout.snapPosition = .right
This is an open source project, so feel free to contribute. How?
- Open an issue;
- Send feedback via email;
- Propose your own fixes, suggestions and open a pull request with the changes.
See all contributors.
SnappingLayout is available under the MIT license. See the LICENSE file for more info.