spacenation / swiftui-sliders

:rocket: SwiftUI Sliders with custom styles
MIT License
793 stars 84 forks source link

Click on slider track should adjust value #37

Closed thompsonate closed 2 years ago

thompsonate commented 3 years ago

With NSSlider on macOS, you can click on the slider track to move the thumb to the clicked position. When running on macOS, these sliders should do the same.

ay42 commented 2 years ago

Hi @thompsonate, This option interactiveTrack is disabled by default. Here is an example on how to enable it.

ValueSlider(value: $value4)
    .valueSliderStyle(
        HorizontalValueSliderStyle(
            track: LinearGradient(
                gradient: Gradient(colors: [.purple, .blue, .purple]),
                startPoint: .leading,
                endPoint: .trailing
            )
            .frame(height: 6)
            .cornerRadius(3),
            thumbSize: CGSize(width: 48, height: 16),
            options: .interactiveTrack
        )
    )
thompsonate commented 2 years ago

This works great, thank you!