Skip to content

abramchuk-v/CardViews

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CardViews

Collection like a Badoo or Tinder cards

CardViews Swift 3.0

Sample

If you want to create something like a badoo card, then enjoy it!

Installation

SWCardView requires iOS 10.0 or later.

Using CocoaPods

  1. Add the pod SWCardView to your Podfile.

pod 'SWCardView'

  1. Run pod install from Terminal, then open your app's .xcworkspace file to launch Xcode.

Usage

import SWCardView
  1. Register cardView.
let cardView = SwipeCardsView(frame: frame)
cardView.delegate = self
cardView.dataSource = self
self.view.addSubview(cardView)
cardView.reloadData()
  1. Add DataSource and Delegate method.
extension ViewController: SwipeCardViewDelegate {
    func nearOfEnd() {
        obtainNewData()
    }

    func swipedLeft(_ object: Any) {
        //left action
    }

    func swipedRight(_ object: Any) {
        //right action
    }

    func cardTapped(_ object: Any) {
        //tap
    }

    func reachedEnd() {
        //end
    }
}

extension ViewController: SwipeCardViewDataSource {
    func createViewForOverlay(index: Int, swipe: SwipeMode, with frame: CGRect) -> UIView {
        let label = UILabel()
        label.frame.size = CGSize(width: 100, height: 100)
        label.center = CGPoint(x: frame.width / 2, y: frame.height / 2)
        label.text = swipe == .right ? "right" : "left"
        return label
    }

    func rowCount() -> Int {
        return dataArray.count
    }

    func createViewForCard(index: Int, with frame: CGRect) -> UIView {
        let cell = ProblemCell(frame: frame)
        cell.element = dataArray[index]
        return cell
    }
}

Demo

Build and run the testTind project in Xcode to see this pod in action. Have fun.

Contact

Abramchuk Vladislav

License

This project is available under the Apache 2.0 license. See the LICENSE file for more info.