Skip to content

Commit 15e887c

Browse files
committed
Write documentation; increment major version
1 parent ccbfb27 commit 15e887c

File tree

7 files changed

+101
-16
lines changed

7 files changed

+101
-16
lines changed

README.md

+51-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
[![License](https://img.shields.io/cocoapods/l/TactileSlider.svg?style=flat)](https://cocoapods.org/pods/TactileSlider)
66
[![Platform](https://img.shields.io/cocoapods/p/TactileSlider.svg?style=flat)](https://cocoapods.org/pods/TactileSlider)
77

8+
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+
![Animated gif of TactileSliders animating to values](Screenshots/animated.gif)
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+
820
## Example
921

1022
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:
2234
pod 'TactileSlider'
2335
```
2436

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
61+
```
62+
63+
### Changing colors and appearance
64+
65+
```swift
66+
slider.trackBackground = UIColor.black.withAlpha(0.8)
67+
slider.thumbTint = UIColor.blue
68+
slider.cornerRadius = 12
69+
```
70+
71+
### Interface Builder
72+
73+
![screenshot of Xcode Interface Builder demonstrating a TactileSlider being customized using the graphical interface](Screenshots/IBDesignable.png)
74+
2575
## Author
2676

27-
Dale Price, daprice@mac.com
77+
Dale Price ([@dale_price@mastodon.technology](https://mastodon.technology/@dale_price))
2878

2979
## License
3080

Screenshots/IBDesignable.png

43.4 KB
Loading

Screenshots/animated.gif

125 KB
Loading

Screenshots/horizontal.png

12.6 KB
Loading

Screenshots/vertical.png

13.7 KB
Loading

TactileSlider.podspec

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'TactileSlider'
11-
s.version = '0.1.0'
11+
s.version = '1.0.0'
1212
s.summary = 'Easy-to-grab slider control inspired by Control Center and HomeKit.'
1313

1414
# This description is used to generate tags and improve search results.
@@ -26,7 +26,7 @@ A slider control designed to be easy to grab and use because it can be dragged o
2626
s.license = { :type => 'MIT', :file => 'LICENSE' }
2727
s.author = { 'Dale Price' => 'daprice@mac.com' }
2828
s.source = { :git => 'https://github.com/daprice/iOS-Tactile-Slider.git', :tag => s.version.to_s }
29-
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
29+
s.social_media_url = 'https://mastodon.technology/@dale_price'
3030

3131
s.ios.deployment_target = '8.0'
3232
s.swift_version = '4.2'
@@ -38,6 +38,6 @@ A slider control designed to be easy to grab and use because it can be dragged o
3838
# }
3939

4040
# s.public_header_files = 'Pod/Classes/**/*.h'
41-
# s.frameworks = 'UIKit', 'MapKit'
41+
s.frameworks = 'UIKit'
4242
# s.dependency 'AFNetworking', '~> 2.3'
4343
end

TactileSlider/Classes/TactileSlider.swift

+47-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
22
// TactileSlider.swift
3-
// Pods
3+
// Easy-to-grab slider control inspired by Control Center and HomeKit.
44
//
55
// Created by Dale Price on 1/22/19.
66
//
@@ -18,18 +18,29 @@ import UIKit
1818

1919
// MARK: - Public properties
2020

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`
2126
@IBInspectable open var vertical: Bool = false {
2227
didSet {
2328
updateLayerFrames()
2429
}
2530
}
2631

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`
2735
@IBInspectable open var reverseValueAxis: Bool = false {
2836
didSet {
2937
updateLayerFrames()
3038
}
3139
}
3240

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
3344
@IBInspectable open var minimum: Float = 0 {
3445
didSet {
3546
if maximum < minimum { maximum = minimum }
@@ -38,6 +49,10 @@ import UIKit
3849
updateAccessibility()
3950
}
4051
}
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
4156
@IBInspectable open var maximum: Float = 1 {
4257
didSet {
4358
if minimum > maximum { minimum = maximum }
@@ -46,6 +61,8 @@ import UIKit
4661
updateAccessibility()
4762
}
4863
}
64+
65+
/// The current (or starting) value for the slider
4966
@IBInspectable open private(set) var value: Float = 0.5 {
5067
didSet(oldValue) {
5168
if oldValue != value {
@@ -56,25 +73,32 @@ import UIKit
5673
}
5774
}
5875

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
5977
@IBInspectable open var isContinuous: Bool = true
6078

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.
6282
@IBInspectable open var enableTapping: Bool = true
6383

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
6585
@IBInspectable open var scaleUpWhenInUse: Bool = false
6686

87+
/// The color of the track the slider slides along
6788
@IBInspectable open var trackBackground: UIColor = UIColor.darkGray {
6889
didSet {
6990
renderer.trackBackground = trackBackground
7091
}
7192
}
93+
94+
/// The color of the value indicator part of the slider
7295
@IBInspectable open var thumbTint: UIColor = UIColor.white {
7396
didSet {
7497
renderer.thumbTint = thumbTint
7598
}
7699
}
77100

101+
/// The radius of the rounded corners of the slider
78102
@IBInspectable var cornerRadius: CGFloat = 16 {
79103
didSet {
80104
renderer.cornerRadius = cornerRadius
@@ -122,6 +146,12 @@ import UIKit
122146
}
123147

124148
private var _feedbackStyle: Int?
149+
150+
/// The `UIImpactFeedbackGenerator.FeedbackStyle` used for haptic feedback when the slider reaches either end of its track
151+
///
152+
/// - Important: Only available on iOS 10.0 or later
153+
///
154+
/// - Note: Defaults to `.light` if not set
125155
@available(iOS 10.0, *) open var feedbackStyle: UIImpactFeedbackGenerator.FeedbackStyle {
126156
get {
127157
guard let _feedbackStyle = _feedbackStyle,
@@ -169,12 +199,14 @@ import UIKit
169199
renderer.trackLayer.addSublayer(renderer.thumbLayer)
170200

171201
updateLayerFrames()
172-
173-
if #available(iOS 10.0, *) {
174-
feedbackStyle = .light
175-
}
176202
}
177203

204+
/// Sets the value of the slider.
205+
///
206+
/// - 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.
178210
open func setValue(_ newValue: Float, animated: Bool) {
179211
value = min(maximum, max(minimum, newValue))
180212
renderer.setValue(value, animated: animated)
@@ -195,7 +227,10 @@ import UIKit
195227
sendActions(for: .valueChanged)
196228
}
197229

198-
public func valueAsPercentage(locale: Locale = Locale.current) -> String? {
230+
/// Returns a string containing the value of the slider as a percentage
231+
///
232+
/// - Parameter locale: The `Locale` to format the value for; defaults to `Locale.current`
233+
open func valueAsPercentage(locale: Locale = Locale.current) -> String? {
199234
let valueNumber = (value - minimum) / (maximum - minimum) as NSNumber
200235
let valueFormatter = NumberFormatter()
201236
valueFormatter.numberStyle = .percent
@@ -205,7 +240,7 @@ import UIKit
205240
return valueFormatter.string(from: valueNumber)
206241
}
207242

208-
open func updateAccessibility() {
243+
private func updateAccessibility() {
209244
accessibilityValue = valueAsPercentage()
210245
}
211246

@@ -299,7 +334,7 @@ import UIKit
299334
renderer.updateBounds(bounds)
300335
}
301336

302-
// returns the position along the value axis for a given control value
337+
/// returns the position along the value axis for a given control value
303338
func positionForValue(_ value: Float) -> CGFloat {
304339
switch direction {
305340
case .rightToLeft, .leftToRight:
@@ -318,7 +353,7 @@ import UIKit
318353
}
319354
}
320355

321-
// returns the control value for a given position along the value axis
356+
/// returns the control value for a given position along the value axis
322357
func valueForPosition(_ position: CGFloat) -> Float {
323358
switch direction {
324359
case .rightToLeft, .leftToRight:
@@ -328,7 +363,7 @@ import UIKit
328363
}
329364
}
330365

331-
// returns whichever axis in a Point represents the value axis for this particular slider
366+
/// returns whichever axis in a Point represents the value axis for this particular slider
332367
func valueAxisFrom(_ point: CGPoint, accountForDirection: Bool = true) -> CGFloat {
333368
switch direction {
334369
case .leftToRight:

0 commit comments

Comments
 (0)