测试测试中 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2018年2月 |
SwiftSwift 版本 | 4 |
SPM支持 SPM | ✗ |
由 Filip Dujmusic 维护。
# in your tvOS target
use_frameworks!
pod 'TVMultiPicker'
为了使用此库,需要创建 MultiPickerViewController<T>
实例。
<T>
是选择器生成的值的类型。
用户必须提供 ProcessDataAction: ([(index: Int, value: String)]) -> T?
动作
可以从给定的多个选择器的选择项数组中生成值。
选择器定义方式如下
let examplePicker = PickerDefinition(
data: ["Item 1", "Item 2"], // Items displayed in horizontal list
cellWidth: 100, // Width of each item cell (can be nil for auto-calculated width!)
initialValueIndex: 0, // "Item 1" will initially be focused
remembersLastFocusedElement: true // Remembers focused element when horizontal list regains focus
)
例如,让我们创建一个简单的多选择器,包含两个具有自动计算单元格宽度的选择器。
第一个将是一个性别选择器,而第二个将代表国家选择器。
最后我们希望以 String
格式获取选择值:“男性,克罗地亚”。
用户选择值后,我们将取消选择器并打印值到控制台。
let pickerVC = MultiPickerViewController<String>(
[
PickerDefinition(
data: ["Male", "Female"],
cellWidth: nil,
initialValueIndex: 0,
remembersLastFocusedElement: true
),
PickerDefinition(
data: ["Croatia", "France", "Italy", "Spain"],
cellWidth: nil,
initialValueIndex: 0,
remembersLastFocusedElement: true
)
],
initialPickerIndex: 0, // Initially focused picker will be gender picker
configuration: .defaultConfig, // UI configuration set to default red/black style
processDataAction: { pickedValues in
return pickedValues[0].value + ", " + pickedValues[1].value
},
valuePickedAction: { finalValue, picker in
picker.dismiss(animated: true, completion: nil)
print(finalValue)
}
)
// present pickerVC and everything is set-up
库还包含预制的日期选择器。可以使用以下方式使用它
let picker = MultiPicker.datePicker(
startYear: 1900, // Lower year bound
initialYear: 1990, // Initially focused year
configuration: .defaultConfig
) { date, picker in
picker.dismiss(animated: true, completion: nil)
print(date)
}