• Stars
    star
    476
  • Rank 92,280 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

UISlider clone with multiple thumbs and values, range highlight, optional snap intervals, optional value labels, either vertical or horizontal.

MultiSlider

UISlider clone with multiple thumbs and values, range highlight, optional snap values, optional value labels, either vertical or horizontal.

Swift Version Build Status License CocoaPods Compatible Platform PRs Welcome

Features

  • Multiple thumbs
  • Range slider (optional) - track color between thumbs different from track color outside thumbs
  • Vertical (optional)
  • Value labels (optional)
  • Snap steps or specific snap values (optional)
  • Haptic feedback (optional)
  • Configurable thumb image, minimum and maximum images.
  • Configurable track width, color, rounding.

Usage

let slider = MultiSlider()
slider.minimumValue = 1    // default is 0.0
slider.maximumValue = 5    // default is 1.0

slider.value = [1, 4.5, 5]

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

SwiftUI Usage

MultiValueSlider(value: $valueArray, minimumValue: 1, maximumValue: 5)

The properties mentioned below can be used as modifiers, or passed as arguments to the MultiValueSlider initializer. For example:

MultiValueSlider(value: $valueArray, outerTrackColor: .lightGray)
    .thumbTintColor(.blue)

Getting multiple thumb values

Use value to get all thumbs values, and draggedThumbIndex to find which thumb was last moved.

func sliderChanged(slider: MultiSlider) {
    print("thumb \(slider.draggedThumbIndex) moved")
    print("now thumbs are at \(slider.value)") // e.g., [1.0, 4.5, 5.0]
}

Range slider

slider.outerTrackColor = .lightGray // outside of first and last thumbs

Vertical / horizontal orientation

slider.orientation = .horizontal // default is .vertical
slider.isVertical = false // same effect, but accessible from Interface Builder

Value labels

slider.valueLabelPosition = .left // .notAnAttribute = don't show labels
slider.valueLabelAlternatePosition = true // alternate left and right positions (false by default)
slider.isValueLabelRelative = true // show differences between thumbs instead of absolute values
slider.valueLabelFormatter.positiveSuffix = " 𝞡s"
slider.valueLabelColor = .green
slider.valueLabelFont = someFont

For more control over the label text:

slider.valueLabelTextForThumb = { thumbIndex, thumbValue in
    ["Parasol", "Umbrella"][thumbIndex] + " \(thumbValue)"
}

Snap steps

slider.snapStepSize = 0.5 // default is 0.0, i.e. don't snap
slider.snapValues = [1, 2, 4, 8] // specify specific snap values instead uniform steps
slider.isHapticSnap = false // default is true, i.e. generate haptic feedback when sliding over snap values
slider.snapImage = UIImage(systemName: "circle.fill") // default: no image

Changing Appearance

slider.tintColor = .cyan // color of track
slider.thumbTintColor = .blue // color of thumbs
slider.trackWidth = 32
slider.hasRoundTrackEnds = true
slider.showsThumbImageShadow = false // wide tracks look better without thumb shadow
slider.centerThumbOnTrackEnd = true // when thumb value is minimum or maximum, align it's center with the track end instead of its edge

Images

// add images at the ends of the slider:
slider.minimumImage = UIImage(named: "clown")
slider.maximumImage = UIImage(named: "cloud")

// change image for all thumbs:
slider.thumbImage = UIImage(named: "balloon")

// or let each thumb have a different image:
slider.thumbViews[0].image = UIImage(named: "ball")
slider.thumbViews[1].image = UIImage(named: "club")

Distance/Overlap Between Thumbs

// allow thumbs to overlap:
slider.keepsDistanceBetweenThumbs = false

// make thumbs keep a greater distance from each other (default = half the thumb size):
slider.distanceBetweenThumbs = 3.14

Disabling/freezing thumbs

slider.disabledThumbIndices = [1, 3]

Requirements

  • iOS 9.0+
  • Xcode 10

Installation

CocoaPods:

pod 'MultiSlider'

Legacy versions:

Swift version MultiSlider version
4.0 (Xcode 9.4) pod 'MiniLayout', '~> 1.2.1'
pod 'MultiSlider', '~> 1.6.0'
3 pod 'MiniLayout', '~> 1.1.0'
pod 'MultiSlider', '~> 1.1.2'
2.3 pod 'MiniLayout', '~> 1.0.1'
pod 'MultiSlider', '~> 1.0.1'

Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/yonat/MultiSlider", from: "2.1.6")
]

Meta

@yonatsharon

https://github.com/yonat/MultiSlider

More Repositories

1

StepProgressView

Step-by-step progress view with labels and shapes. A good replacement for UIActivityIndicatorView and UIProgressView.
Swift
376
star
2

MultiSelectSegmentedControl

UISegmentedControl remake that supports selecting multiple segments, vertical stacking, combining text and images.
Swift
299
star
3

RadioGroup

The missing iOS radio buttons group.
Swift
190
star
4

SelectionList

Simple single-selection or multiple-selection checklist, based on UITableView
Swift
119
star
5

MultiToggleButton

Multiple state tap-to-toggle UIButton (like old camera flash button)
Swift
83
star
6

CheckmarkCollectionViewCell

UICollectionViewCell with checkbox when it isSelected and empty circle when not - like Photos.app "Select" mode.
Swift
65
star
7

CameraBackground

Show camera layer as a background to any UIView
Swift
64
star
8

BatteryView

Simple battery shaped UIView
Swift
51
star
9

BadgeLabel

Simple animatable badge, based on UILabel and using CALayer
Objective-C
49
star
10

MockImagePicker

Mock UIImagePickerController for testing camera based UI in simulator
Swift
22
star
11

ContactsChangeNotifier

Which contacts changed outside your iOS app? Better CNContactStoreDidChange notification: Get real changes, without the noise.
Swift
17
star
12

EditableList

Simple List of UITextField-s based on UITableViewController
Objective-C
13
star
13

SweeterSwift

Extensions and syntactic sugar to enrich the Swift standard library, iOS frameworks, and SwifterSwift.
Swift
11
star
14

EasyBackgroundRefresh

Easy background refresh registration, scheduling, execution, and completion. BGTaskScheduler for the lazy.
Swift
10
star
15

YONAutoComplete

Add auto-completion to a UITextField
Objective-C
9
star
16

MiniLayout

Minimal AutoLayout convenience layer. Program constraints succinctly. ⚠️ Moved into https://github.com/yonat/SweeterSwift
Swift
8
star
17

AvailableHapticFeedback

Unified haptic feedback interface for all subclasses of UIFeedbackGenerator, with availability checks for iOS 9.
Swift
8
star
18

SwiftQuality

Common configuration files for SwiftLint and SwiftFormat
Ruby
6
star
19

smart_ptr

Simple C++ Smart Pointer Classes
C
3
star
20

versionit

Simple bash script to change Xcode project version and build number, create git tag, and update podspec.
Shell
3
star
21

pointainer

STL Extensions for containers of pointers
C++
2
star
22

Blinker

mac app that reminds you to blink by displaying animated blinking eyes on your screen at regular intervals
Swift
2
star
23

SystemFontOverride

Easy font branding for your iOS app
Swift
2
star
24

DirectoryUploader

Automatically upload all files saved in source directory, and then delete the uploaded files.
Swift
1
star