BGStatePicker is a component that allows showing different states and selecting one.
BGStatePicker implement is a UIControl that receive a datasource to show different states.
import BGStatePicker
//....
let openState = BGStateable()
openState.stateText = "Open"
openState.stateBackgroundColor = .greenColor()
let closedState = BGStateable()
closedState.stateText = "Close"
closedState.stateBackgroundColor = .redColor()
let statusStates = [openState, closedState]
statePickerView.datasource = self
statePickerView.reloadData()
extension ViewController: BGStatePickerDatasource {
func numberOfState(statePickerView: BGStatePickerView) -> Int {
return statusStates.count
}
func stateForIndex(statePickerView: BGStatePickerView, index: Int) -> BGStateable {
return statusStates[index]
}
}
}
BGStatePicker inherits from UIControl and implements the .ValueChanged event.
//in viewDidLoad{
//....
statePickerView.addTarget(self, action: #selector(pickState(_:)), forControlEvents: [.ValueChanged])
//...
}
...
func pickState(sender: BGStatePickerView) {
if let state = sender.selectedValue { // BGStateable
print("You pick state \(state.stateText)")
}
}
github "grimabe/BGStatePicker" ~> 0.2.0
pod "BGStatePicker", "~> 0.2.0"
BGStatePicker requires iOS 8 or later.
Benjamin Grima
BGStatePicker is licensed under the MIT License.