EPDeckView
is an easy-to-use Swift library that provides a deck of views that can be swiped or thrown left/right (inspired by the Tinder app).
- iOS 8.0+
- Xcode 7.2
Clone this repo and manually add the source files to project.
If you are using CocoaPods just add in your podfile:
pod 'EPDeckView'
or if you want to get the latest release:
pod 'EPDeckView', :git => 'https://github.com/EvansPie/EPDeckView.git'
- Create a new view (from storyboard or programmatically) inheriting
EPDeckView
and add it on your view. Conform toEPDeckViewDataSource
&EPDeckViewDelegate
as you would with aUITableView
and set the view's delegate & data source.
class ViewController: UIViewController, EPDeckViewDataSource, EPDeckViewDelegate {
@IBOutlet weak var deckView: EPDeckView!
// Array that keeps a reference to our cards.
private var cardViews: [EPCardView] = []
override func viewDidLoad() {
super.viewDidLoad()
// Set the deckView's delegate & data source.
self.deckView.delegate = self
self.deckView.dataSource = self
}
}
- Return the number of cards that you wish to add in the deck, as you would do with
UITableViewDataSource
.
func numberOfCardsInDeckView(deckView: EPDeckView) -> Int {
return 6
}
- Create your cards as you would do with
UITableViewCell
. Your cards must inheritEPCardView
.
func deckView(deckView: EPDeckView, cardViewAtIndex index: Int) -> EPCardView {
// Create a TestView to be added as a card in the deck.
let testView: TestView = TestView(frame: CGRectMake(0,0,240,240))
// Keep a reference so you can pass the nib's buttons to the delegate functions.
self.cardViews.append(testView)
return testView
}
That's it! Don't forget to reload your deck (after viewDidLayoutSubviews()
if you are using autolayout).
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.deckView.reloadCards()
}
For a detailed guide on how to use the features visit here
-
Modify the animation of the deck and the card being dragged.
-
Throw a card left/right.
-
Monitor the card's movement and the card's button tap.
-
Bring back the latest card thrown.
Evangelos Pittas, [email protected]
EPDeckView is available under the MIT license. See the LICENSE file for more info.