SwipeableTableViewCell is a quite easy-to-use UITableViewCell subclass which allows you to add multiple highly customizable swipe actions.
Specify "SwipeableTableViewCell" in your Cartfile
:
github "teambition/SwipeableTableViewCell"
Import "SwipeableTableViewCell":
import SwipeableTableViewCell
Configure cell in the data source like this:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as? SwipeableTableViewCell
if cell == nil {
cell = SwipeableTableViewCell(style: .default, reuseIdentifier: "Cell")
}
// assign delegate if needed
cell!.delegate = self
// configure cell swipe actions
let deleteTitle = NSAttributedString(string: "删除", attributes: [.foregroundColor: UIColor.white, .font: UIFont.systemFont(ofSize: 15)])
var deleteAction = SwipeableCellAction(title: deleteTitle, image: UIImage(named: "delete-icon"), backgroundColor: UIColor.red) { _ in
// do something when "deleteAction" is selected
}
let laterTitle = NSAttributedString(string: "稍后处理", attributes: [.foregroundColor: UIColor.white, .font: UIFont.systemFont(ofSize: 15)])
var laterAction = SwipeableCellAction(title: laterTitle, image: UIImage(named: "later-icon"), backgroundColor: UIColor.blue) { _ in
// do something when "laterAction" is selected
}
deleteAction.width = 100
deleteAction.verticalSpace = 6
laterAction.width = 100
laterAction.verticalSpace = 6
cell!.actions = [deleteAction, laterAction]
// other configurations
cell!.textLabel?.text = "Cell"
return cell!
}
func swipeableCell(_ cell: SwipeableTableViewCell, isScrollingToState state: SwipeableCellState) {
// do something
}
func swipeableCellSwipeEnabled(_ cell: SwipeableTableViewCell) -> Bool {
// cell swipe enabled or not, default value is true
}
func allowMultipleCellsSwipedSimultaneously() -> Bool {
// allow multiple cells swiped simultaneously or not, default value is false
}
func swipeableCellDidEndScroll(_ cell: SwipeableTableViewCell) {
// do something
}
iOS 8.0
SwipeableTableViewCell is released under the MIT license. See LICENSE for details.
Have a question? Please open an issue!