Giter Site home page Giter Site logo

swiftreorder's Introduction

SwiftReorder

SwiftReorder is a UITableView extension that lets you add long-press drag-and-drop reordering to any table view. It's robust, lightweight, and fully customizable.

Demo

Features

  • Smooth animations
  • Automatic edge scrolling
  • Works with multiple table sections
  • Customizable shadow, scaling, and transparency effects

Installation

CocoaPods

To integrate SwiftReorder into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'SwiftReorder', '~> 5.0'

Manually

You can integrate SwiftReorder into your project manually by copying the contents of the Source folder into your project.

Usage

Setup

  • Add the following line to your table view setup.
override func viewDidLoad() {
    // ...
    tableView.reorder.delegate = self
}
  • Add this code to the beginning of your tableView(_:cellForRowAt:).
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if let spacer = tableView.reorder.spacerCell(for: indexPath) {
        return spacer
    }
    // ...
}
  • Implement the tableView(_:reorderRowAt:to:) delegate method, and others as necessary.
extension MyViewController: TableViewReorderDelegate {
    func tableView(_ tableView: UITableView, reorderRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
        // Update data model
    }
}

This method is analogous to the UITableViewDataSource method tableView(_:moveRowAt:to:). However, it may be called multiple times in the course of one drag-and-drop action.

Customization

SwiftReorder exposes several properties for adjusting the style of the reordering effect. For example, you can add a scaling effect to the selected cell:

tableView.reorder.cellScale = 1.05

Or adjust the shadow:

tableView.reorder.shadowOpacity = 0.5
tableView.reorder.shadowRadius = 20

swiftreorder's People

Contributors

adamshin avatar colinhumber avatar larrylegend avatar matuella 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.