Easy to use UITableViewCell implementing swiping to trigger actions.

Overview

SwipyCell

Awesome Build Status Swift Copatibility CocoaPods Compatible Platform GitHub license Twitter

Swipeable UITableViewCell inspired by the popular Mailbox App, implemented in Swift.

Preview

Exit Mode

The .exit mode is the original behavior, known from the Mailbox app.

Toggle Mode

The .toggle is another behavior where the cell will bounce back after swiping it.

Installation

Swift Package Manager (recommended)

Swift Package Manger is Apples first party tool for managing distribution of source code, aimed at making it easy to share your code and reuse others’ code.

To use the SwipyCell library in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/moritzsternemann/SwipyCell", .upToNextMinor(from: "4.1.0")),

CocoaPods

CocoaPods is a dependency manager for Cocoa projects.

To integrate SwipyCell into your project using CocoaPods, add it to your Podfile:

pod 'SwipyCell', '~> 4.1'

Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

To integrate SwipyCell into your project using Carthage, add it to your Cartfile:

github "moritzsternemann/SwipyCell" >= 4.1

Usage

Example

A complete example is available in the Example directory. The following code is a very basic example:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! SwipyCell
    cell.selectionStyle = .gray
    cell.contentView.backgroundColor = UIColor.white

    let checkView = viewWithImageName("check")
    let greenColor = UIColor(red: 85.0 / 255.0, green: 213.0 / 255.0, blue: 80.0 / 255.0, alpha: 1.0)

    let crossView = viewWithImageName("cross")
    let redColor = UIColor(red: 232.0 / 255.0, green: 61.0 / 255.0, blue: 14.0 / 255.0, alpha: 1.0)

    let clockView = viewWithImageName("clock")
    let yellowColor = UIColor(red: 254.0 / 255.0, green: 217.0 / 255.0, blue: 56.0 / 255.0, alpha: 1.0)

    let listView = viewWithImageName("list")
    let brownColor = UIColor(red: 206.0 / 255.0, green: 149.0 / 255.0, blue: 98.0 / 255.0, alpha: 1.0)

    cell.defaultColor = tableView.backgroundView?.backgroundColor
    cell.delegate = self

    cell.textLabel?.text = "Switch Mode Cell"
    cell.detailTextLabel?.text = "Swipe to switch"

    cell.addSwipeTrigger(forState: .state(0, .left), withMode: .toggle, swipeView: checkView, swipeColor: greenColor, completion: { cell, trigger, state, mode in
        print("Did swipe \"Checkmark\" cell")
    })

    cell.addSwipeTrigger(forState: .state(1, .left), withMode: .toggle, swipeView: crossView, swipeColor: redColor, completion: { cell, trigger, state, mode in
        print("Did swipe \"Cross\" cell")
    })

    cell.addSwipeTrigger(forState: .state(0, .right), withMode: .toggle, swipeView: clockView, swipeColor: yellowColor, completion: { cell, trigger, state, mode in
        print("Did swipe \"Clock\" cell")
    })

    cell.addSwipeTrigger(forState: .state(1, .right), withMode: .toggle, swipeView: listView, swipeColor: brownColor, completion: { cell, trigger, state, mode in
        print("Did swipe \"List\" cell")
    })

    return cell
}

SwipyCellState

SwipyCellState represents a sliding state, for example the first state to the left of the cell.
The possible values are

  • .none - center position of the cell
  • .state(index, side) - index of the state from near to far and side of the state, each relative to the cell

SwipyCellMode

SwipyCellMode as shown above.

SwipyCellTriggerBlock

SwipyCellTriggerBlock is a typealias for

(SwipyCell, SwipyCellTrigger, SwipyCellState, SwipyCellMode) -> Void

Add swipe triggers to cells

Adding swipe triggers to cells is easy using this method:

func addSwipeTrigger(forState: SwipyCellState, withMode: SwipyCellMode, swipeView: UIView, swipeColor: UIColor, completion: SwipyCellTriggerBlock)
  • forState at which the trigger should activate
  • withMode for the trigger
  • swipeView: e.g. display an icon
  • swipeColor: backgroundColor of the swipeView
  • completion: called after the swipe gesture has ended, only if the trigger point was reached

Delegate

SwipyCell provides three delegate methods in order to track the users behaviors.

// When the user starts swiping the cell this method is called
func swipyCellDidStartSwiping(_ cell: SwipyCell)

// When the user ends swiping the cell this method is called
func swipyCellDidFinishSwiping(_ cell: SwipyCell, atState state: SwipyCellState, triggerActivated activated: Bool)

// When the user is dragging, this method is called with the percentage from the border
func swipyCell(_ cell: SwipyCell, didSwipeWithPercentage percentage: CGFloat, currentState state: SwipyCellState, triggerActivated activated: Bool)

Configuration

All configurable options are defined in the SwipyCellConfig.shared singleton object. Every new cell has these options set as defaults. To alter the defaults simply change the variables of the SwipyCellConfig singleton object.

Trigger Points

Trigger points are defined in the triggerPoints<CGFloat, SwipyCellState> dictionary in either the configuration singleton or each cell individually.
Each key marks the swiping percentage for a trigger point; the corresponding value is an identifier to reference the trigger point later. A negative key marks a point on the right side of the cell (slide to the left), a positive key marks a point on the left side of the cell (slide to the right).
To modify the trigger points there are a couple of methods available on every cell as well as the configuration singleton:

// Set a new trigger point for the given state
func setTriggerPoint(forState state: SwipyCellState, at point: CGFloat)

// Set a new trigger point for the given index on BOTH sides of the cell
func setTriggerPoint(forIndex index: Int, at point: CGFloat)

// Overwrite all existing trigger points with the given new ones
func setTriggerPoints(_ points: [CGFloat: SwipyCellState])
// The Integer parameter is the index for BOTH sides of the cell
func setTriggerPoints(_ points: [CGFloat: Int])

// Overwrite all existing trigger points with new ones in order of the array on BOTH sides
func setTriggerPoints(points: [CGFloat])

// Get all existing trigger points
func getTriggerPoints() -> [CGFloat: SwipyCellState]

// Clear all existing trigger points
func clearTriggerPoints()

Defaults: 25% and 75% on each side

swipeViewPadding

var swipeViewPadding: CGFloat

swipeViewPadding is the padding between the swipe view and and the outer edge of the cell.

Default: 24.0

shouldAnimateSwipeViews

var shouldAnimateSwipeViews: Bool

shouldAnimateSwipeViews sets if the swipeView should move with the cell while sliding or stay at the outer edge.

Default: true

defaultSwipeViewColor

var defaultSwipeViewColor: UIColor

defaultSwipeViewColor is the color of the swipe when the current state is .none.

Default: UIColor.white

Resetting the cell position

You can animate the cell back to it's default position when using .exit mode using the swipeToOrigin(_:) method. This could be useful if your app asks the user for confirmation and the user want's to cancel the action.

cell.swipeToOrigin {
    print("Swiped back")
}

Author

I'm Moritz Sternemann, a computer-science student at Technical University of Munich.

License

SwipyCell is available under the MIT license. See LICENSE file for more info.

Comments
  • exposure of slidingView subview (swipeView) attribute

    exposure of slidingView subview (swipeView) attribute

    Thanks! It's so easy to subclass and implement without breaking anything.

    It would be great if we could reference back to the swipeView and change it within closure.

    feature request 
    opened by DazChong 6
  • Swipe Image with text

    Swipe Image with text

    Hello,

    I want to implement swipe image with text. and when image change according to text also change.\ so can you please help me?

    Thanks, Mohsinali Matiya

    opened by mohsinalimat 4
  • Update to Swift 3

    Update to Swift 3

    The goal is to update the repo to work with Swift 3 and to adopt the cosmetical changes in Swift 3 (e.g. camelCase enum values).

    Please drop a comment if you are interested so others know that you are working on this issue. Have fun coding! 😄

    help wanted Hacktoberfest 
    opened by moritzsternemann 4
  • Inaccessible due to 'internal' protection level

    Inaccessible due to 'internal' protection level

    Hi thanks @moritzsternemann and any other contributors. I'm trying to access color1 of the cell argument in the delegate but I get an error:

    "'color1' is inaccessible due to 'internal' protection level."

    Any help would be appreciated!

    error

    opened by niazoff 3
  • Made it possible to subclass SwipyCell for custom tableview cells

    Made it possible to subclass SwipyCell for custom tableview cells

    Apparently the SwipyCell class wasn't subclass-able with new access rules for Swift 3. See solution to: http://stackoverflow.com/questions/39072300/xcode-8-cannot-inherit-from-non-open-class

    I needed a custom cell based on the SwipyCell class, so I just changed types access modifier from 'public' to 'open'. Use if you want :-)

    opened by Msurrow 2
  • build with iphone5 target fails

    build with iphone5 target fails

    My project builds fine if I set the target (simulator) to iphone 5s or above, however it fails with the following errors for iphone 5.

    /Users/msurrow/Development/bAdmin-ios/bAdmin-ios/PracticeTableViewController.swift:12:7: Type 'PracticeTableViewController' does not conform to protocol 'SwipyCellDelegate'
    
    /Users/msurrow/Development/bAdmin-ios/SwipyCell.SwipyCellDelegate:2:17: Protocol requires function 'swipyCellDidStartSwiping' with type '(SwipyCell) -> ()'; do you want to add a stub?
    
    /Users/msurrow/Development/bAdmin-ios/SwipyCell.SwipyCellDelegate:3:17: Protocol requires function 'swipyCellDidFinishSwiping(_:atState:triggerActivated:)' with type '(SwipyCell, SwipyCellState, Bool) -> ()'; do you want to add a stub?
    
    /Users/msurrow/Development/bAdmin-ios/SwipyCell.SwipyCellDelegate:4:17: Protocol requires function 'swipyCell(_:didSwipeWithPercentage:currentState:triggerActivated:)' with type '(SwipyCell, CGFloat, SwipyCellState, Bool) -> ()'; do you want to add a stub?
    
    /Users/msurrow/Development/bAdmin-ios/bAdmin-ios/PracticeTableViewController.swift:164:9: Value of type 'PracticeTableViewCell' has no member 'setSwipeGesture'
    
    /Users/msurrow/Development/bAdmin-ios/bAdmin-ios/PracticeTableViewController.swift:176:9: Value of type 'PracticeTableViewCell' has no member 'setSwipeGesture'
    

    Swipycell vers. 3.2.0 from pods

    opened by Msurrow 1
  • Swipe gesture disappears

    Swipe gesture disappears

    I started realizing that after one of my SwipyCell subclasses done in Storyboard go off the screen and come back, my swiping gesture doesn't work anymore.

    opened by niazoff 1
  • Why set the cell.contentView.backgroundColor white?

    Why set the cell.contentView.backgroundColor white?

    I have a TableView with clear background color contentView. I found that the contentView.backgroundColor will be set UIColor.white when the contentView.backgroundColor != nil and backgroundColor == UIColor.clear. So when I swipe the cell there's a white background appeared in above of the cell.

    The code is in line 136 SwipyCell.swift.

    opened by talisk 1
  • Swift3

    Swift3

    Hey! Thanks for the cool library. I've updated it to Swift 3 and removed boilerplate code. If you don't mind, I can get rid of extra parentheses, self usage, etc

    closes #1

    opened by serejahh 1
  • Logo Design Proposal

    Logo Design Proposal

    Good day Sir @moritzsternemann , I am Tobaloidee and I am a graphics designer and i want to contribute to your good project by designing a logo for it as i've noticed it doesn't have one yet. I will be doing it as a gift for free. If you will permit me i will start my design asap. Thanks and best regards!

    opened by Tobaloidee 0
  • Background misbehaviour when swiping from right to left

    Background misbehaviour when swiping from right to left

    Hi, I just tested the Example and switched from .state(0, .left) to .state(0, .right) and this strange behaviour occurred. Do you have any hint how to solve it? From left to right it works fine.

    untitled

    untitled

    opened by LeonardoCardoso 0
Releases(4.1.0)
Owner
Moritz Sternemann
Swift, VueJS, C++, spaces • CS @ TUM •  WWDC Scholar / Swift Student Challenge Winner • Photography, Motion Design, Skiing
Moritz Sternemann
Convenient UITableViewCell subclass that implements a swippable content to trigger actions (similar to the Mailbox app).

MCSwipeTableViewCell An effort to show how one would implement a UITableViewCell like the one we can see in the very well executed Mailbox iOS app. Pr

Ali Karagoz 3k Dec 16, 2022
A PageView Swiping to the left will go to previous page and swiping to the right will go to next page

PageView This package creates a PageView. Swiping to the left will go to previous page and swiping to the right will go to next page. You can find how

null 0 Oct 20, 2021
An easy to use UITableViewCell subclass that allows to display swippable buttons with a variety of transitions.

MGSwipeTableCell MGSwipeTableCell is an easy to use UITableViewCell subclass that allows to display swipeable buttons with a variety of transitions. T

Imanol Fernandez 7k Dec 26, 2022
An easy-to-use UITableViewCell subclass that implements a swippable content view which exposes utility buttons (similar to iOS 7 Mail Application)

SWTableViewCell An easy-to-use UITableViewCell subclass that implements a swipeable content view which exposes utility buttons (similar to iOS 7 Mail

Christopher Wendel 7.2k Dec 31, 2022
TopicEventBus is Easy to use, type safe way of implementing Publish–subscribe design pattern.

TopicEventBus Publish–subscribe design pattern implementation framework, with ability to publish events by topic. (NotificationCenter extended alterna

Matan Abravanel 55 Nov 29, 2021
NSFileProviderManager.signalEnumerator does not trigger update of UIDocumentBrowserViewController

FB9715717 Which area are you seeing an issue with? FileProvider Framework Incorrect/Unexpected Behavior Subject NSFileProviderManager.signalEnumerator

Marcin Krzyzanowski 2 Dec 11, 2021
TriggerSlider is a simple SwiftUI trigger slider

TriggerSlider is a simple SwiftUI trigger slider which can be used instead of a button, e.g. in a situation where the

Dominik Butz 4 Dec 16, 2022
ActionBee is a programmable pasteboard action trigger.

ActionBee ActionBee is a programmable pasteboard action trigger. Preview Video It can be used to clean your URL in text. To see code or import this mo

Derek Jones 2 Aug 24, 2022
ZoomTransitioning provides a custom transition with image zooming animation and swiping the screen edge.

ZoomTransitioning Overview ZoomTransitioning provides a custom transition with image zooming animation. When you use this library with UINavigationCon

WorldDownTown 673 Dec 27, 2022
PhotoSlider is a simple photo slider and can delete slider with swiping.

PhotoSlider is a simple photo slider and can delete slider with swiping.

Daichi Nakajima 247 Nov 30, 2022
The horizontal swiping navigation like on Facebook Messenger.

UIMenuScroll UIMenuScroll creating menu how on Facebook Messenger on take photo Installation CocoaPods is a dependency manager for Cocoa projects. You

Aleksey Pleshkov 18 Aug 9, 2022
🔥 A multi-directional card swiping library inspired by Tinder

Made with ❤️ by Mac Gallagher Features ?? Advanced swipe recognition based on velocity and card position ?? Manual and programmatic actions ?? Smooth

Mac Gallagher 754 Dec 28, 2022
Gravity Switch - A dynamic game that integrates swiping and tapping to create a fun interactive game

GravitySwitch Gravity Switch is a dynamic game that integrates swiping and tappi

null 3 Nov 19, 2022
This repo shows how to setup and use GitHub Actions as a CI for Swift Packages

GACalc This repo shows how to setup and use GitHub Actions as a CI for Swift Packages. Available environments on GitHib List of the all available envi

Michał Tynior 0 Nov 3, 2021
This repo shows how to set up and use GitHub Actions as a CI for Swift Packages

SwiftPackageWithGithubActionsAsCI This repo shows how to set up and use GitHub Actions as a CI for Swift Packages. Available environments on GitHib Li

Michał Tynior 0 Nov 3, 2021
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.

wobbly See Wobbly in action (examples) Add a drop of honey ?? to your project wobbly has a bunch of cool, fun, and easy to use iOS animations for you

Sagaya Abdulhafeez 150 Dec 23, 2021
(Animate CSS) animations for iOS. An easy to use library of iOS animations. As easy to use as an easy thing.

wobbly See Wobbly in action (examples) Add a drop of honey ?? to your project wobbly has a bunch of cool, fun, and easy to use iOS animations for you

Sagaya Abdulhafeez 150 Dec 23, 2021
Light wrapper of UITableViewCell that allows extra customization for tvOS

TvOSCustomizableTableViewCell Light wrapper of UITableViewCell that allows extra customization for tvOS If you would like to have the same level of cu

Zattoo 31 Nov 9, 2022
Optimizing UITableViewCell For Fast Scrolling

DWURecyclingAlert Your code usually has less than ten milliseconds to run before it causes a frame drop.1 Visualize Bad Drawings On The Fly Injects 4

diwup 564 Dec 6, 2022
Template auto layout cell for automatically UITableViewCell height calculating

UITableView-FDTemplateLayoutCell Overview Template auto layout cell for automatically UITableViewCell height calculating. Basic usage If you have a se

null 10k Dec 31, 2022