TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jul 2016 |
SPMSupports SPM | ✗ |
Maintained by DingHub.
There are only visible cards in memory, after you drag and removed the top one, it will be reused as the last one.
内存中只会生成可见的卡片,顶部的卡片被划走之后,会作为最后一张卡片循环利用。
pod surpported:
支持pod :
target ‘xxx’ do
use_frameworks!
pod ‘SwipeableCards’
end
Here is an example:
用法示例:
@IBOutlet weak var cards: SwipeableCards!
var cardsData = [Int]()
override func viewDidLoad() {
super.viewDidLoad()
makeCardsData()
cards.dataSource = self
cards.delegate = self
}
func makeCardsData() {
for i in 0..<100 {
cardsData.append(i)
}
}
// SwipeableCardsDataSource methods
func numberOfTotalCards(cards: SwipeableCards) -> Int {
return cardsData.count
}
func viewFor(cards: SwipeableCards, index: Int, reusingView: UIView?) -> UIView {
var label: UILabel? = view as? UILabel
if label == nil {
let size = cards.frame.size
let labelFrame = CGRect(x: 0, y: 0, width: size.width - 30, height: size.height - 20)
label = UILabel(frame: labelFrame)
label!.textAlignment = .Center
label!.layer.cornerRadius = 5
}
label!.text = String(cardsData[index])
label!.layer.backgroundColor = Color.randomColor().CGColor
return label!
}
// SwipeableCardsDelegate
func cards(cards: SwipeableCards, beforeSwipingItemAtIndex index: Int) {
print("Begin swiping card \(index)!")
}
func cards(cards: SwipeableCards, didLeftRemovedItemAtIndex index: Int) {
print("<--\(index)")
}
func cards(cards: SwipeableCards, didRightRemovedItemAtIndex index: Int) {
print("\(index)-->")
}
func cards(cards: SwipeableCards, didRemovedItemAtIndex index: Int) {
print("index of removed card:\(index)")
}