OTSortButton is a UIButton library useful for sorting.
・Change appearance for each parts and sort types.
1.Set OTSortButton to Custom Class and Module of your UIButton.
The appearance can be set with IBInspectable.
2.Import and connect IBOutlet
import OTSortButton
@IBOutlet var sortButtonCollection: [OTSortButton]!
3.If you want to set the key on the button, please set it as the sort key
@IBOutlet weak var yourSortButton: OTSortButton!
yourSortButton.sortKey = "yourKey"
4.Connect IBAction
@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()
}
Add this to your Podfile.
pod 'OTSortButton'
Add this to your Cartfile.
github "PKPK-Carnage/OTSortButton"
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.