A SwiftUI control for selecting a continuous range of numeric values with two draggable thumbs.
- Two draggable thumbs for lower and upper bounds
- Support for both
DoubleandIntranges - Configurable step increments for discrete values
- Minimum distance constraint between thumbs
- Customizable appearance (colors, sizes)
- RTL layout support
- VoiceOver accessibility support
- iOS 18.0+
- macOS 26+
- Swift 6.2+
Add the following to your Package.swift:
dependencies: [
.package(url: "https://github.com/tomokisun/swiftui-closed-range-slider.git", from: "1.0.0")
]Or add it via Xcode: File > Add Package Dependencies... and enter the repository URL.
import ClosedRangeSlider
struct ContentView: View {
@State private var price: ClosedRange<Double> = 20...60
var body: some View {
VStack(spacing: 24) {
Text("Price: \(Int(price.lowerBound)) – \(Int(price.upperBound))")
ClosedRangeSlider($price, in: 0...100, step: 1)
}
.padding()
}
}@State private var ageRange: ClosedRange<Int> = 18...65
ClosedRangeSlider($ageRange, in: 0...100, step: 1)Ensure a minimum gap between the two thumbs:
ClosedRangeSlider($range, in: 0...100, minimumDistance: 10)React to drag start and end events:
ClosedRangeSlider($range, in: 0...100) { isEditing in
if isEditing {
// User started dragging
} else {
// User finished dragging
}
}ClosedRangeSlider($range, in: 0...100)
.rangeSliderTint(.orange)ClosedRangeSlider($range, in: 0...100)
.rangeSliderTrackHeight(8)
.rangeSliderTrackColor(.gray.opacity(0.3))ClosedRangeSlider($range, in: 0...100)
.rangeSliderThumbSize(CGSize(width: 28, height: 28))
.rangeSliderThumbColor(.blue)For accessibility labels:
ClosedRangeSlider($range, in: 0...100)
.rangeSliderValueFormatter { value in
"$\(Int(value))"
}MIT License