Latest 1.0.3
Homepage https://github.com/d-32/DMSwipeCards
License MIT
Platforms ios 8.0
Authors

Version
License
twitter: @dylan36032

image

Features

  • Swift 3
  • Custom views for the card & overlay
  • Generic
  • Dynamically add new cards on top or on the bottom
  • Lazy view loading

Setup

pod 'DMSwipeCards'

Usage

First import the module:

import DMSwipeCards

Next create an instance of a DMSwipeCardsView:
(Element can be your custom model, or just String)

let swipeView = DMSwipeCardsView<Element>(frame: frame,
                                          viewGenerator: viewGenerator,
                                          overlayGenerator: overlayGenerator)

Views get loaded lazy, so you have to provide DMSwipeCardsView with a ViewGenerator and optionally an OverlayGenerator.

let viewGenerator: (String, CGRect) -> (UIView) = { (element: Element, frame: CGRect) -> (UIView) in
  // return a UIView here
}

let overlayGenerator: (SwipeMode, CGRect) -> (UIView) = { (mode: SwipeMode, frame: CGRect) -> (UIView) in
  // return a UIView here
}

Adding cards

To add new cards, just call the addCards method with an array of the previously defined Element:

swipeView.addCards([Element], onTop: true)

Delegate

DMSwipeCardsView has a delegate property so you can get informed when a card has been swipped. The delegate has to implement following methods:

func swipedLeft(_ object: Any)
func swipedRight(_ object: Any)
func cardTapped(_ object: Any)
func reachedEndOfStack()

The object parameter is guarenteed to have the type Element. Sadly generics don’t work here.

Example

For a nice working demo sample, please take a look the Example project.
To run the example, first run pod install in the Example directory.

Credits

Loosly based on TinderSimpleSwipeCards

Latest podspec

{
    "name": "DMSwipeCards",
    "version": "1.0.3",
    "summary": "Tinder like card interface",
    "description": "Written in Swift 3, supports custom views for the card and the overlay. Views get loaded lazily, so there's no issues in loading a huge amount of cards.",
    "homepage": "https://github.com/d-32/DMSwipeCards",
    "screenshots": [
        "https://raw.githubusercontent.com/D-32/DMSwipeCards/master/Screenshots/01.png",
        "https://raw.githubusercontent.com/D-32/DMSwipeCards/master/Screenshots/02.png",
        "https://raw.githubusercontent.com/D-32/DMSwipeCards/master/Screenshots/03.png"
    ],
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Dylan Marriott": "[email protected]"
    },
    "source": {
        "git": "https://github.com/d-32/DMSwipeCards.git",
        "tag": "1.0.3"
    },
    "social_media_url": "https://twitter.com/dylan36032",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "DMSwipeCards/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This