SelectableStackView
SelectableStackView is a customizable and easy to use UI element for showing and managing selectable elements in a stack written in Swift.
Features
- Supports any number of elements
- Supports any type of elements given that it should conform to SelectionObservableView protocol
- Automatically manages elements
- Allows to manually manage elements if needed
- Supports single/multiple selection states
- Can automatically handle no selection case
- Use in code or from interface builder
- Has a delegate to observe selection
Requirements
- iOS 10.0+
- Xcode 11+
- Swift 5.2+
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler.
Use Xcode’s new Swift Packages option, which is located within the File menu.
Usage example
Add an arranged subview
import SelectableStackView
selectableStackView.addArrangedSubview(yourView) // make sure that your view conform to ObservableBySelectableStackView protocol
Select an view from code
import SelectableStackView
selectableStackView.select(true, at: someIndex) // if view at given index doesnt exist, nothing will happen
Receive selection events
import SelectableStackView
// 1. Conform to SelectableStackViewDelegate protocol
class SomeClass: SelectableStackViewDelegate {
let selectableStackView = SelectableStackView()
init() {
// 2. Set delegate
selectableStackView.delegate = self
}
// MARK: - SelectableStackViewDelegate
func didSelect(_ select: Bool, at index: Index, on selectableStackView: SelectableStackView) {
// handle selection
}
}
Advanced
Turn on logging
selectableStackView.loggingEnabled = on // enable logging if needed
Turn off delegate notifications on self selection
import SelectableStackView
class SomeClass: SelectableStackViewDelegate {
var shouldNotifyAboutSelfSelection: Bool { true }
}
License
SelectableStackView is released under the MIT license. See LICENSE for details.