Collection like a Badoo or Tinder cards
If you want to create something like a badoo card, then enjoy it!
SWCardView requires iOS 10.0 or later.
Using CocoaPods
- Add the pod
SWCardView
to your Podfile.
pod 'SWCardView'
- Run
pod install
from Terminal, then open your app's.xcworkspace
file to launch Xcode.
import SWCardView
- Register cardView.
let cardView = SwipeCardsView(frame: frame)
cardView.delegate = self
cardView.dataSource = self
self.view.addSubview(cardView)
cardView.reloadData()
- 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
}
}
Build and run the testTind
project in Xcode to see this pod in action.
Have fun.
Abramchuk Vladislav
This project is available under the Apache 2.0 license. See the LICENSE file for more info.