Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adamshin/SwiftReorder
Easy UITableView drag-and-drop cell reordering
https://github.com/adamshin/SwiftReorder
ios swift swift-3 swift-library ui-components uikit uitableview
Last synced: 3 months ago
JSON representation
Easy UITableView drag-and-drop cell reordering
- Host: GitHub
- URL: https://github.com/adamshin/SwiftReorder
- Owner: adamshin
- License: mit
- Created: 2016-08-13T05:27:33.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2020-04-14T18:54:04.000Z (over 4 years ago)
- Last Synced: 2024-04-24T18:57:44.765Z (6 months ago)
- Topics: ios, swift, swift-3, swift-library, ui-components, uikit, uitableview
- Language: Swift
- Homepage:
- Size: 405 KB
- Stars: 398
- Watchers: 8
- Forks: 75
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - SwiftReorder - Add drag-and-drop reordering to any table view with just a few lines of code. Robust, lightweight, and completely customizable. [e] (UI / Table View / Collection View)
- awesome-ios-star - SwiftReorder - Add drag-and-drop reordering to any table view with just a few lines of code. Robust, lightweight, and completely customizable. [e] (UI / Table View / Collection View)
README
# SwiftReorder
**NOTE: Some users have encountered compatibility issues when using this library with recent versions of iOS. For apps targeting iOS 11 and up, it's recommended to use the built-in [UITableView drag and drop API](https://developer.apple.com/documentation/uikit/views_and_controls/table_views/supporting_drag_and_drop_in_table_views) instead.**
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](Resources/demo.gif)
## 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`:
```ruby
pod 'SwiftReorder', '~> 7.2'
```### Carthage
To integrate SwiftReorder into your Xcode project using Carthage, specify it in your `Cartfile`:
```
github "adamshin/SwiftReorder" ~> 7.2
```Remember to [add SwiftReorder to your Carthage build phase](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos):
```
$(SRCROOT)/Carthage/Build/iOS/SwiftReorder.framework
```and
```
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/SwiftReorder.framework
```### 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.
```swift
override func viewDidLoad() {
// ...
tableView.reorder.delegate = self
}
```
* Add this code to the beginning of your `tableView(_:cellForRowAt:)`.
```swift
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.
```swift
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:
```swift
tableView.reorder.cellScale = 1.05
```
Or adjust the shadow:
```swift
tableView.reorder.shadowOpacity = 0.5
tableView.reorder.shadowRadius = 20
```