测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可协议 | MIT |
发布最新发布 | 2017年10月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
由Viktor Rutberg维护。
要运行示例项目,请克隆仓库,并首先从Example目录运行`pod install`。
VRPicker通过CocoaPods提供。要安装它,只需将以下行添加到您的Podfile中
即可。
pod "VRPicker"
VRPicker
类是泛型的,它接受一个类型参数,该参数必须是VRPickerItem
的子类。您在这里传递的类型将是您的项目类。VRPicker
使用一个VRPickerConfiguration
实例实例化(它也接受一个类型参数)和一个CGRect
作为框架
struct PickerItem: VRPickerItem {
let number: Int
var description: String {
return "\(number) yrs"
}
}
let config = VRPickerConfiguration<PickerItem>(items: ...)
let pickerView = VRPicker<PickerItem>(with: config, frame: .zero)
pickerView.didSelectItem = { item in
print(item)
}
如上例所示,应将`didSelectItem`属性设置为接收关于当前选中哪个项目的更新。
VRPickerConfiguration
,用于实例化VRPicker
实例,包含可以配置的各种属性。
所有配置属性都有默认值。
items: [T]
(无默认值)要显示在选择器中的项列表。这些项必须遵守协议VRPickerItem
,该协议扩展了CustomStringConvertible
。
defaultSelectedIndex: Int
(默认值:0)选择器初始化时应该选择哪个索引。
selectedFont: UIFont
(默认值:UIFont.boldSystemFont(ofSize: 20)
)用于当前选中项目的字体。
selectedFontColor: UIColor
(默认值:UIColor.white
)用于当前选中项目的字体颜色。
nonSelectedFont: UIFont
(默认值:UIFont.systemFont(ofSize: 14)
)用于未选中项目的字体。
nonSelectedFontColor: UIColor
(默认值:UIColor.black
)用于未选中项目的字体颜色。
selectionRadiusInPercent: Double
(默认值:0.3
)选择圆的半径,以百分比。 (1.0 = 100 %)
selectionBackgroundColor: UIColor
(默认值:UIColor.green
)用于选择圆的背景颜色。
gradientColors: [UIColor]
(默认值:[UIColor.white.withAlphaComponent(0.8), UIColor.white.withAlphaComponent(0)]
)用于左右两边的渐变颜色数组。
gradientWidthInPercent: Double
(默认值:0.4
)整个选择器宽度的渐变宽度,以百分比。 (1.0 = 100 %)
gradientPosition: GradientPosition
(默认值:GradientPosition.above
)渐变的位置,在上部或下部。
itemWidth: Int
(默认值:100
)项目使用的宽度,以点为单位。
sliderVelocityCoefficient: Double
(默认值:60
)滚动视图的速度系数。
维克托·鲁特堡,[email protected]
VRPicker 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。