SelectableStackView 是一个可定制且易于使用的 UI 元素,用于在 Swift 中编写的堆栈中显示和管理可选择的元素。
Swift Package Manager 是一种用于自动执行 Swift 代码分发的工具,并已集成到 swift
编译器中。
使用 Xcode 的新 Swift Packages 选项,该选项位于 File 菜单中。
import SelectableStackView
selectableStackView.addArrangedSubview(yourView) // make sure that your view conform to ObservableBySelectableStackView protocol
import SelectableStackView
selectableStackView.select(true, at: someIndex) // if view at given index doesnt exist, nothing will happen
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
}
}
selectableStackView.loggingEnabled = on // enable logging if needed
import SelectableStackView
class SomeClass: SelectableStackViewDelegate {
var shouldNotifyAboutSelfSelection: Bool { true }
}
SelectableStackView 在 MIT 许可证下发布。请参阅 LICENSE 了解详细信息。