Skip to content

Latest commit

 

History

History
103 lines (74 loc) · 2.92 KB

README.md

File metadata and controls

103 lines (74 loc) · 2.92 KB

MultiSlider

UISlider clone with multiple thumbs and values, optional snap intervals, optional value labels.

Swift Version Build Status License CocoaPods Compatible
Platform PRs Welcome

Usage

let slider   = MultiSlider()
slider.minimumValue = 1    // default is 0.0
slider.maximumValue = 5    // default is 1.0
slider.snapStepSize = 0.5  // default is 0.0, i.e. don't snap

slider.value = [1, 4.5, 5]

slider.addTarget(self, action: #selector(sliderChanged(_:)), forControlEvents: .valueChanged) // continuous changes
slider.addTarget(self, action: #selector(sliderDragEnded(_:)), forControlEvents: . touchUpInside) // sent when drag ends

Getting Multiple Thumb Values

func sliderChanged(slider: MultiSlider) {
    print("\(slider.value)") // e.g., [1.0, 4.5, 5.0]
}

Changing Appearance

slider.orientation = .horizontal
slider.thumbImage   = UIImage(named: "balloon")
slider.minimumImage = UIImage(named: "clown")
slider.maximumImage = UIImage(named: "cloud")
slider.tintColor = .cyan
slider.trackWidth = 5
slider.hasRoundTrackEnds = true
slider.showsThumbImageShadow = false

Adding Labels Showing Thumb Value

slider.valueLabelPosition = .Left // .NotAnAttribute = don't show labels
slider.isValueLabelRelative = true // shows differences instead of absolute values

Disabling/Freezing Thumbs

slider.disabledThumbIndices = [1, 3]

Requirements

  • iOS 9.0+
  • Xcode 9

Installation

CocoaPods:

pod 'MultiSlider'

For legacy Swift 2.3:

pod 'MultiSlider', '~> 1.0.1'

Manually:

Copy Sources/*.swift and MiniLayout.swift to your Xcode project.

TODO

  • Fix IB presentation. (dlopen error "image not found", thumbs should be vertically centered and evenly distributed.)

Meta

@yonatsharon

https://github.com/yonat/MultiSlider