https://github.com/frog-frog/otsortbutton
OTSortButton is a UIButton library useful for sorting.
https://github.com/frog-frog/otsortbutton
ios iphone swift swift3 uibutton
Last synced: 3 months ago
JSON representation
OTSortButton is a UIButton library useful for sorting.
- Host: GitHub
- URL: https://github.com/frog-frog/otsortbutton
- Owner: Frog-Frog
- License: mit
- Created: 2017-09-14T11:53:46.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-16T14:35:09.000Z (over 8 years ago)
- Last Synced: 2025-08-02T00:13:37.268Z (11 months ago)
- Topics: ios, iphone, swift, swift3, uibutton
- Language: Swift
- Size: 81.1 KB
- Stars: 12
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OTSortButton
## Description
OTSortButton is a UIButton library useful for sorting.
## Features
・Change appearance for each parts and sort types.
## Demo

## Usage
1.Set OTSortButton to Custom Class and Module of your UIButton.

The appearance can be set with IBInspectable.

2.Import and connect IBOutlet
```swift
import OTSortButton
@IBOutlet var sortButtonCollection: [OTSortButton]!
```
3.If you want to set the key on the button, please set it as the sort key
```swift
@IBOutlet weak var yourSortButton: OTSortButton!
yourSortButton.sortKey = "yourKey"
```
4.Connect IBAction
```swift
@IBAction func tappedSortButton(_ sender: OTSortButton) {
for sortButton in sortButtonCollection {
if sortButton == sender {
let key = sortButton.sortKey
switch sortButton.sortType {
case .none:
sortButton.sortType = .ascend
// Sort ascend here.
//e.g. sortedArray = yourArray.sorted(by: { $0[key]! < $1[key]! })
case .ascend:
sortButton.sortType = .descend
// Sort descend here.
//e.g. sortedArray = yourArray.sorted(by: { $0[key]! > $1[key]! })
case .descend:
sortButton.sortType = .none
// Undo here.
//e.g. sortedArray = yourArray
}
} else {
sortButton.sortType = .none
}
}
yourView.reloadData()
}
```
## Install
### CocoaPods
Add this to your Podfile.
```PodFile
pod 'OTSortButton'
```
### Carthage
Add this to your Cartfile.
```Cartfile
github "PKPK-Carnage/OTSortButton"
```
## Help
If you want to support this framework, you can do these things.
* Please let us know if you have any requests for me.
I will do my best to live up to your expectations.
* You can make contribute code, issues and pull requests.
I promise to confirm them.
## Licence
[MIT](https://github.com/PKPK-Carnage/OTSortButton/blob/master/LICENSE)
## Author
[PKPK-Carnage🦎](https://github.com/PKPK-Carnage)