Skip to content

Latest commit

 

History

History
61 lines (39 loc) · 2.44 KB

README.md

File metadata and controls

61 lines (39 loc) · 2.44 KB

DiscreteSlider

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.

Table of contents

Requirements

  • SwiftUI
  • iOS 14.0+, macCatalyst 14.0+, macOS 11.0+, visionOS 1.0+

Installation

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.

Usage

DiscreteSlider is highly customizable, you could use it with it's default appearance or create your own.

Quick start

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

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:

Acknowledgements

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.

License

DiscreteSlider is under the terms and conditions of the MIT license.