SwipeCellKit
Swipeable UITableViewCell/UICollectionViewCell based on the stock Mail.app, implemented in Swift.
About
A swipeable UITableViewCell
or UICollectionViewCell
with support for:
- Left and right swipe actions
- Action buttons with: text only, text + image, image only
- Haptic Feedback
- Customizable transitions: Border, Drag, and Reveal
- Customizable action button behavior during swipe
- Animated expansion when dragging past threshold
- Customizable expansion animations
- Support for both
UITableView
andUICollectionView
- Accessibility
- Dark Mode
Background
Check out my blog post on how SwipeCellKit came to be.
Demo
Transition Styles
The transition style describes how the action buttons are exposed during the swipe.
Border
Drag
Reveal
Customized
Expansion Styles
The expansion style describes the behavior when the cell is swiped past a defined threshold.
None
Selection
Destructive
Customized
Requirements
- Swift 5.0
- Xcode 10.3+
- iOS 9.0+
Installation
CocoaPods (recommended)
Carthage
Swift Package Manager
Documentation
Read the [docs][docsLink]. Generated with jazzy. Hosted by GitHub Pages.
Usage for UITableView
Set the delegate
property on SwipeTableViewCell
:
Adopt the SwipeTableViewCellDelegate
protocol:
Optionally, you can implement the editActionsOptionsForRowAt
method to customize the behavior of the swipe actions:
Usage for UICollectionView
Set the delegate
property on SwipeCollectionViewCell
:
Adopt the SwipeCollectionViewCellDelegate
protocol:
Optionally, you can implement the editActionsOptionsForItemAt
method to customize the behavior of the swipe actions:
Transitions
Three built-in transition styles are provided by SwipeTransitionStyle
:
- .border: The visible action area is equally divide between all action buttons.
- .drag: The visible action area is dragged, pinned to the cell, with each action button fully sized as it is exposed.
- .reveal: The visible action area sits behind the cell, pinned to the edge of the table view, and is revealed as the cell is dragged aside.
See Customizing Transitions for more details on customizing button appearance as the swipe is performed.
Transition Delegate
Transition for a SwipeAction
can be observered by setting a SwipeActionTransitioning
on the transitionDelegate
property. This allows you to observe what percentage is visible and access to the underlying UIButton
for that SwipeAction
.
Expansion
Four built-in expansion styles are provided by SwipeExpansionStyle
:
- .selection
- .destructive (like Mail.app)
- .destructiveAfterFill (like Mailbox/Tweetbot)
- .fill
Much effort has gone into making SwipeExpansionStyle
extremely customizable. If these built-in styles do not meet your needs, see Customizing Expansion for more details on creating custom styles.
The built-in .fill
expansion style requires manual action fulfillment. This means your action handler must call SwipeAction.fulfill(style:)
at some point during or after invocation to resolve the fill expansion. The supplied ExpansionFulfillmentStyle
allows you to delete or reset the cell at some later point (possibly after further user interaction).
The built-in .destructive
, and .destructiveAfterFill
expansion styles are configured to automatically perform row deletion when the action handler is invoked (automatic fulfillment). Your deletion behavior may require coordination with other row animations (eg. inside beginUpdates
and endUpdates
). In this case, you can easily create a custom SwipeExpansionStyle
which requires manual fulfillment to trigger deletion:
NOTE: You must call
SwipeAction.fulfill(with style:)
at some point while/after your action handler is invoked to trigger deletion. Do not calldeleteRows
directly.
Advanced
See the Advanced Guide for more details on customization.