Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Last active February 27, 2023 20:12
Show Gist options
  • Select an option

  • Save sturdysturge/0b3557d78837817f5df19ba783d2a0fe to your computer and use it in GitHub Desktop.

Select an option

Save sturdysturge/0b3557d78837817f5df19ba783d2a0fe to your computer and use it in GitHub Desktop.
import SwiftUI
@available(iOS 16.0, *)
struct ContentView: View {
@State var sliderValue = Double(0)
var body: some View {
VStack {
Text(String(sliderValue))
Slider(value: $sliderValue, in: 0...100)
CustomSlider(value: $sliderValue, in: 0...100)
}
}
}
struct CustomSlider: View {
@Binding var value: Double
let bounds: ClosedRange<Double>
internal init(value: Binding<Double>,
in bounds: ClosedRange<Double>) {
self._value = value
self.bounds = bounds
}
var body: some View {
ZStack {
ProgressView(value: value / bounds.upperBound)
.padding(.horizontal, 1)
SliderThumbView(value: $value, bounds: bounds)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment