GithubHelp home page GithubHelp logo

hongxinhope / swipeabletableviewcell Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alibaba-archive/swipeabletableviewcell

0.0 1.0 0.0 528 KB

A quite easy-to-use UITableViewCell subclass which allows you to add multiple highly customizable swipe actions.

License: MIT License

Swift 100.00%

swipeabletableviewcell's Introduction

SwipeableTableViewCell

SwipeableTableViewCell is a quite easy-to-use UITableViewCell subclass which allows you to add multiple highly customizable swipe actions.

Example

How To Get Started

Carthage

Specify "SwipeableTableViewCell" in your Cartfile:

github "teambition/SwipeableTableViewCell"

Usage

1. TableViewController

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!
}

2. Implement delegate if needed

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
}

Minimum Requirement

iOS 8.0

Release Notes

License

SwipeableTableViewCell is released under the MIT license. See LICENSE for details.

More Info

Have a question? Please open an issue!

swipeabletableviewcell's People

Contributors

d-wang avatar hongxinhope avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.