DiscreteSlider – slider which allows user to choose value only from predefined set of data. Slider may receive any types of options, you may pass set of integers or strings, or any other type. Written using SwiftUI
.
- SwiftUI
- iOS 14.0+, macCatalyst 14.0+, macOS 11.0+, visionOS 1.0+
DiscreteSlider could be installed via Swift Package Manager. Open Xcode and go to File -> Add Packages..., search https://github.com/hengyu/DiscreteSlider.git
, and add the package as one of your project's dependency.
DiscreteSlider is highly customizable, you could use it with it's default appearance or create your own.
To create a slider simply instantiate DiscreteSlider
class:
DiscreteSlider(
options: [20, 40, 60, 80, 100], // Options that is used as a data source for the slider.
selectedItem: $mySelectedItem // Binding to the property that will store the selected item.
)
This action will create a slider with default appearance.
Customization of a slider is not a big deal. DiscreteSlider provides three protocols that is used to represent the components of a slider: SliderTrack
, SliderTick
, SliderHandle
and SliderLabel
. By implementing each of the protocol you will be able to build your custom slider.
Some examples of what you can achieve by customizing slider:
DiscreteSlider is originated from the STDiscreteSlider created by onl1ner. We have made several updates based on the original work. And we want to express our heartful appreciation to the creator and contributers of STDiscreteSlider.
DiscreteSlider is under the terms and conditions of the MIT license.