You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A slider control designed to be easy to grab and use because it can be dragged or tapped from anywhere along its track, similar to the sliders in Control Center and HomeKit.
9
+
10
+

11
+
12
+
## Features
13
+
14
+
- Can be dragged or (optionally) tapped to set a value
15
+
- Supports horizontal and vertical orientation in either direction
16
+
- IBDesignable – colors, values, rounded corners, and behavior can be customized in Interface Builder or programatically
17
+
- Adjustable haptic feedback (iOS 10+)
18
+
- VoiceOver support
19
+
8
20
## Example
9
21
10
22
To run the example project, clone the repo, and run `pod install` from the Example directory first.
@@ -22,9 +34,47 @@ it, simply add the following line to your Podfile:
22
34
pod 'TactileSlider'
23
35
```
24
36
37
+
## Usage
38
+
39
+
```swift
40
+
let slider =TactileSlider(frame: someRect)
41
+
42
+
slider.minimumValue=1
43
+
slider.maximumValue=10
44
+
45
+
slider.setValue(3.8, animated: true)
46
+
```
47
+
48
+
### Setting orientation and direction
49
+
50
+
```swift
51
+
slider.vertical=true
52
+
slider.reverseValueAxis=true
53
+
```
54
+
55
+
### Adjusting behavior
56
+
57
+
```swift
58
+
slider.isContinuous=false
59
+
slider.enableTapping=false// allow or disallow tapping anywhere on the slider track to instantly set a value
60
+
slider.scaleUpWhenInUse=true// make the slider puff up slightly while being dragged
Copy file name to clipboardexpand all lines: TactileSlider/Classes/TactileSlider.swift
+47-12
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
//
2
2
// TactileSlider.swift
3
-
// Pods
3
+
// Easy-to-grab slider control inspired by Control Center and HomeKit.
4
4
//
5
5
// Created by Dale Price on 1/22/19.
6
6
//
@@ -18,18 +18,29 @@ import UIKit
18
18
19
19
// MARK: - Public properties
20
20
21
+
/// If true, the slider will move in the vertical direction; if false, horizontal.
22
+
///
23
+
/// - Note: You are responsible for setting dimensions/layout constraints on the control in a way that makes sense for the orientation you set.
24
+
///
25
+
/// - SeeAlso: `reverseValueAxis`
21
26
@IBInspectableopenvarvertical:Bool=false{
22
27
didSet {
23
28
updateLayerFrames()
24
29
}
25
30
}
26
31
32
+
/// If false (default), the minimum value will be at the bottom or left of the slider, depending on `vertical`; if true, the minimum will be at the top or right.
33
+
///
34
+
/// - SeeAlso: `vertical`
27
35
@IBInspectableopenvarreverseValueAxis:Bool=false{
28
36
didSet {
29
37
updateLayerFrames()
30
38
}
31
39
}
32
40
41
+
/// The minimum value for the slider
42
+
///
43
+
/// - Note: If you set this to above `maximum` or `value`, those values will be changed to match
33
44
@IBInspectableopenvarminimum:Float=0{
34
45
didSet {
35
46
if maximum < minimum { maximum = minimum }
@@ -38,6 +49,10 @@ import UIKit
38
49
updateAccessibility()
39
50
}
40
51
}
52
+
53
+
/// The maximum value for the slider
54
+
///
55
+
/// - Note: If you set this to below `minimum` or `value`, those values will be changed to match
41
56
@IBInspectableopenvarmaximum:Float=1{
42
57
didSet {
43
58
if minimum > maximum { minimum = maximum }
@@ -46,6 +61,8 @@ import UIKit
46
61
updateAccessibility()
47
62
}
48
63
}
64
+
65
+
/// The current (or starting) value for the slider
49
66
@IBInspectableopenprivate(set)varvalue:Float=0.5{
50
67
didSet(oldValue){
51
68
if oldValue != value {
@@ -56,25 +73,32 @@ import UIKit
56
73
}
57
74
}
58
75
76
+
/// If true, will send `valueChanged` actions at every point during a movement of the slider; if false, will only send when the user lifts their finger
59
77
@IBInspectableopenvarisContinuous:Bool=true
60
78
61
-
// If true, a single tap anywhere in the slider will set it to that value
79
+
/// If true, a single tap anywhere in the slider will set it to that value
80
+
///
81
+
/// - Remark: Users may accidentally activate this feature while trying to make very small adjustments. If the context lends to making very small adjustments with the slider, consider disabling this feature.
62
82
@IBInspectableopenvarenableTapping:Bool=true
63
83
64
-
// If true, the slider will animate its scale when it is being dragged
84
+
/// If true, the slider will animate its scale when it is being dragged
65
85
@IBInspectableopenvarscaleUpWhenInUse:Bool=false
66
86
87
+
/// The color of the track the slider slides along
/// - Parameter newValue: the value to set the slider to
207
+
/// - Parameter animated: whether or not to perform an asynchronous visual animation of the slider transitioning to the new value
208
+
///
209
+
/// - Postcondition: If the value passed in is greater than `minimum` and less than `maximum`, the `value` of the slider will be set to that value, otherwise it will be capped to within that range.
0 commit comments