Giter Club home page Giter Club logo

collectionswipablecellextension's Introduction

CollectionSwipableCellExtension

It is the extension for UICollectionView and UITableView which appends buttons to a cell and shows them on cell swiping.

Features:

  • swipe to delete gesture
  • doesn’t require subclassing of cell class, it’s more useful in case when a third-party cell is already used.
  • the buttons UI are fully customised by providing own layout.
  • right-to-left languages support

Swipe to delete example

Install

Carthage

github "KosyanMedia/CollectionSwipableCellExtension" ~> 0.0.1

Using

Initialize the extension object with UITableView or UICollectionView and set a delegate.
isEnabled property allows to activate/deactivate functionality.

swipableExtension = CollectionSwipableCellExtension(with: tableView)
swipableExtension?.delegate = self
swipableExtension?.isEnabled = true

Implement methods of CollectionSwipableCellExtensionDelegate protocol, which returns a layout for buttons and defines what cells are swipable.

func isSwipable(itemAt indexPath: IndexPath) -> Bool {
    return true
}

func swipableActionsLayout(forItemAt indexPath: IndexPath) -> CollectionSwipableCellLayout? {
    let actionLayout = CollectionSwipableCellOneButtonLayout(buttonWidth: 100, insets: .zero, direction: .leftToRight)
    actionLayout.action = { [weak self] in
        //do something
    }

    return actionLayout
}

Call resetSwipableActions() in UITableViewDelegate in order to exclude problems with cell's reuse.

func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    cell.resetSwipableActions()
}

or UICollectionViewDelegate

func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
    cell.resetSwipableActions()
}

Layout customization

We provide one simple layout CollectionSwipableCellOneButtonLayout. You can customize it by subclassing or create your own layout which implements CollectionSwipableCellLayout protocol.

collectionswipablecellextension's People

Contributors

glassoff avatar kattouf avatar lorienman avatar voidless avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.