A wheel control in SwiftUI.
Goal: provide a control that allows the user to set an arbitrary floating point value within a range, with fine precision.
Proposed solution: a wheel control with multiple speeds.
![]() |
---|
![]() |
---|
![]() |
---|
The control applies to a variable of type Float via binding.
The parent view (or an associated model) defines the bound value, which is passed to the control, together with the range of allowed values for the variable, an orientation (vertical, horizontal or automatically inferred from view geometry) and an optional commit callback which, if defined, is called in the DragGesture's onCommit callback (this is useful to apply changes only when interaction concludes rather than on all updates).
struct ContentView: View {
@State private var value = Float(1.0)
var body: some View {
VStack(alignment: .leading) {
Text("\(value, specifier: "%.2f")")
WheelControl(value: $value, range: 0.0...100.0, orientation: .horizontal)
.frame(maxHeight: 80)
}
.padding()
}
}
link |
Stars: 1 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics