一种滑块控件,旨在易于抓取和使用,因为它可以在其轨道上的任何位置拖动或点击,类似于控制中心和 HomeKit 中的滑块。 因为这种类型的滑块以图形方式表示对值的直接操作,所以它应该用于实时调整可以在实时直接观察到变化的值(例如音量或灯的亮度)。
要运行示例项目,请克隆仓库,然后首先从 Example 目录运行 pod install
。
iOS 9.0+
TactileSlider 可作为 Swift 包或通过 CocoaPods 获得。
要使用 CocoaPods 安装,只需将以下行添加到您的 Podfile 中
pod 'TactileSlider'
对于使用 Xcode 13 或更高版本的完整文档,请将 TactileSlider 添加为依赖项或下载本地副本,然后选择 Product > Build Documentation。 在以前版本的 Xcode 中,符号文档将出现在快速帮助中。
let slider = TactileSlider(frame: someRect)
slider.minimumValue = 1
slider.maximumValue = 10
slider.setValue(3.8, animated: true)
slider.vertical = true
slider.reverseValueAxis = true
slider.isContinuous = false // send events only at end of gesture vs continuously
slider.enableTapping = false // allow or disallow tapping anywhere on the slider track to instantly set a value
slider.feedbackStyle = .medium // customize haptic feedback when the slider reaches the end
slider.isScrollingEnabled = false // allow or disallow scrolling to adjust the slider using a connected pointing device on iPadOS
slider.precisionRampUpDistance = 10 // enable finer adjustment when moving the slider by amounts smaller than this distance (in screen points)
slider.trackBackground = UIColor.black.withAlpha(0.8) // use translucent black for the slider track
slider.tintColor = UIColor.systemGreen // use dynamic green for the slider thumb
slider.outlineColor = UIColor.gray // color of outline around slider and thumb (if unset, will be determined automatically based on contrast between tintColor and current system appearance)
slider.outlineColorProvider = { slider, suggestedColor -> UIColor? in … } // provide your own closure to set the outline color dynamically
slider.outlineSize = 2 // set thickness of outline
slider.cornerRadius = 12 // size of corner radius; defaults to automatic based on the slider's bounds
slider.isPointerInteractionEnabled = true // display a hover effect when under the pointer on iPadOS
默认情况下,辅助功能递增和递减手势将值更改为滑块范围的 10%,与 UISlider 的行为匹配。 这可以调整
slider.steppingMode = .percentage(5) // specify a percentage to increment/decrement the slider's value by
slider.steppingMode = .stepValue(0.1) // specify a fixed value to increment/decrement the slider's value by
Dale Price (@dale_price@mastodon.online)
TactileSlider 在 MIT 许可下可用。 有关更多信息,请参见 LICENSE 文件。