@@ -34,22 +34,14 @@ import UIKit
3434 public weak var delegate : RangeSeekSliderDelegate ?
3535
3636 /// The minimum possible value to select in the range
37- @IBInspectable public var minValue : CGFloat = 0.0 {
38- didSet {
39- refresh ( )
40- }
41- }
37+ @IBInspectable public var minValue : CGFloat = 0.0
4238
4339 /// The maximum possible value to select in the range
44- @IBInspectable public var maxValue : CGFloat = 100.0 {
45- didSet {
46- refresh ( )
47- }
48- }
40+ @IBInspectable public var maxValue : CGFloat = 100.0
4941
5042 /// The preselected minumum value
5143 /// (note: This should be less than the selectedMaxValue)
52- @IBInspectable public var selectedMinValue : CGFloat = 10 .0 {
44+ @IBInspectable public var selectedMinValue : CGFloat = 0 .0 {
5345 didSet {
5446 if selectedMinValue < minValue {
5547 selectedMinValue = minValue
@@ -59,7 +51,7 @@ import UIKit
5951
6052 /// The preselected maximum value
6153 /// (note: This should be greater than the selectedMinValue)
62- @IBInspectable public var selectedMaxValue : CGFloat = 90 .0 {
54+ @IBInspectable public var selectedMaxValue : CGFloat = 100 .0 {
6355 didSet {
6456 if selectedMaxValue > maxValue {
6557 selectedMaxValue = maxValue
@@ -96,7 +88,6 @@ import UIKit
9688 @IBInspectable public var hideLabels : Bool = false
9789
9890 /// The minimum distance the two selected slider values must be apart. Default is 0.
99-
10091 @IBInspectable public var minDistance : CGFloat = 0.0 {
10192 didSet {
10293 if minDistance < 0.0 {
@@ -106,7 +97,6 @@ import UIKit
10697 }
10798
10899 /// The maximum distance the two selected slider values must be apart. Default is CGFloat.greatestFiniteMagnitude.
109-
110100 @IBInspectable public var maxDistance : CGFloat = . greatestFiniteMagnitude {
111101 didSet {
112102 if maxDistance < 0.0 {
@@ -116,41 +106,22 @@ import UIKit
116106 }
117107
118108 /// The color of the minimum value text label. If not set, the default is the tintColor.
119- @IBInspectable public var minLabelColor : UIColor ? {
120- didSet {
121- minLabel. foregroundColor = minLabelColor? . cgColor
122- }
123- }
109+ @IBInspectable public var minLabelColor : UIColor ?
124110
125111 /// The color of the maximum value text label. If not set, the default is the tintColor.
126- @IBInspectable public var maxLabelColor : UIColor ? {
127- didSet {
128- maxLabel. foregroundColor = maxLabelColor? . cgColor
129- }
130- }
112+ @IBInspectable public var maxLabelColor : UIColor ?
131113
132114 /// Handle slider with custom color, you can set custom color for your handle
133- @IBInspectable public var handleColor : UIColor ? {
134- didSet {
135- leftHandle. backgroundColor = handleColor? . cgColor
136- rightHandle. backgroundColor = handleColor? . cgColor
137- }
138- }
115+ @IBInspectable public var handleColor : UIColor ?
139116
140117 /// Handle slider with custom border color, you can set custom border color for your handle
141- @IBInspectable public var handleBorderColor : UIColor ? {
142- didSet {
143- leftHandle. borderColor = handleBorderColor? . cgColor
144- rightHandle. borderColor = handleBorderColor? . cgColor
145- }
146- }
118+ @IBInspectable public var handleBorderColor : UIColor ?
147119
148120 /// Set slider line tint color between handles
149- @IBInspectable public var colorBetweenHandles : UIColor ? {
150- didSet {
151- sliderLineBetweenHandles. backgroundColor = colorBetweenHandles? . cgColor
152- }
153- }
121+ @IBInspectable public var colorBetweenHandles : UIColor ?
122+
123+ /// The color of the entire slider when the handle is set to the minimum value and the maximum value. Default is nil.
124+ @IBInspectable public var initialColor : UIColor ?
154125
155126 /// If true, the control will mimic a normal slider and have only one handle rather than a range.
156127 /// In this case, the selectedMinValue will be not functional anymore. Use selectedMaxValue instead to determine the value the user has selected.
@@ -171,14 +142,12 @@ import UIKit
171142 /// Handle slider with custom image, you can set custom image for your handle
172143 @IBInspectable public var handleImage : UIImage ? {
173144 didSet {
174- let startFrame : CGRect = CGRect ( x: 0.0 , y: 0.0 , width: 32.0 , height: 32.0 )
175- leftHandle. frame = startFrame
145+ let handleFrame : CGRect = CGRect ( x: 0.0 , y: 0.0 , width: 32.0 , height: 32.0 )
146+ leftHandle. frame = handleFrame
176147 leftHandle. contents = handleImage? . cgImage
177- leftHandle. backgroundColor = UIColor . clear. cgColor
178148
179- rightHandle. frame = startFrame
149+ rightHandle. frame = handleFrame
180150 rightHandle. contents = handleImage? . cgImage
181- rightHandle. backgroundColor = UIColor . clear. cgColor
182151 }
183152 }
184153
@@ -285,6 +254,7 @@ import UIKit
285254 if handleTracking == . none {
286255 updateLineHeight ( )
287256 updateLabelValues ( )
257+ updateColors ( )
288258 updateHandlePositions ( )
289259 updateLabelPositions ( )
290260 }
@@ -294,37 +264,6 @@ import UIKit
294264 return CGSize ( width: UIViewNoIntrinsicMetric, height: 65.0 )
295265 }
296266
297- open override var tintColor : UIColor ! {
298- didSet {
299- guard let color: CGColor = tintColor? . cgColor else { return }
300-
301- CATransaction . begin ( )
302- CATransaction . setAnimationDuration ( 0.5 )
303- CATransaction . setAnimationTimingFunction ( CAMediaTimingFunction ( name: kCAMediaTimingFunctionEaseInEaseOut) )
304-
305- sliderLine. backgroundColor = color
306-
307- if handleColor == nil {
308- leftHandle. backgroundColor = color
309- rightHandle. backgroundColor = color
310- }
311-
312- if minLabelColor == nil {
313- minLabel. foregroundColor = color
314- }
315-
316- if maxLabelColor == nil {
317- maxLabel. foregroundColor = color
318- }
319-
320- if colorBetweenHandles == nil {
321- sliderLineBetweenHandles. backgroundColor = color
322- }
323-
324- CATransaction . commit ( )
325- }
326- }
327-
328267
329268 // MARK: - UIControl
330269
@@ -419,25 +358,19 @@ import UIKit
419358 accessibleElements = [ leftHandleAccessibilityElement, rightHandleAccessibilityElement]
420359
421360 // draw the slider line
422- sliderLine. backgroundColor = tintColor. cgColor
423361 layer. addSublayer ( sliderLine)
424362
425363 // draw the track distline
426- sliderLineBetweenHandles. backgroundColor = tintColor. cgColor
427364 layer. addSublayer ( sliderLineBetweenHandles)
428365
429366 // draw the minimum slider handle
430367 leftHandle. cornerRadius = handleDiameter / 2.0
431- leftHandle. backgroundColor = tintColor. cgColor
432368 leftHandle. borderWidth = handleBorderWidth
433- leftHandle. borderColor = handleBorderColor? . cgColor
434369 layer. addSublayer ( leftHandle)
435370
436371 // draw the maximum slider handle
437372 rightHandle. cornerRadius = handleDiameter / 2.0
438- rightHandle. backgroundColor = tintColor. cgColor
439373 rightHandle. borderWidth = handleBorderWidth
440- rightHandle. borderColor = handleBorderColor? . cgColor
441374 layer. addSublayer ( rightHandle)
442375
443376 let handleFrame : CGRect = CGRect ( x: 0.0 , y: 0.0 , width: handleDiameter, height: handleDiameter)
@@ -452,22 +385,12 @@ import UIKit
452385 minLabel. alignmentMode = kCAAlignmentCenter
453386 minLabel. frame = labelFrame
454387 minLabel. contentsScale = UIScreen . main. scale
455- if let cgColor = minLabelColor? . cgColor {
456- minLabel. foregroundColor = cgColor
457- } else {
458- minLabel. foregroundColor = tintColor. cgColor
459- }
460388 layer. addSublayer ( minLabel)
461389
462390 maxLabelFont = UIFont . systemFont ( ofSize: labelFontSize)
463391 maxLabel. alignmentMode = kCAAlignmentCenter
464392 maxLabel. frame = labelFrame
465393 maxLabel. contentsScale = UIScreen . main. scale
466- if let cgColor = maxLabelColor? . cgColor {
467- maxLabel. foregroundColor = cgColor
468- } else {
469- maxLabel. foregroundColor = tintColor. cgColor
470- }
471394 layer. addSublayer ( maxLabel)
472395
473396 refresh ( )
@@ -541,6 +464,39 @@ import UIKit
541464 }
542465 }
543466
467+ private func updateColors( ) {
468+ let isInitial : Bool = selectedMinValue == minValue && selectedMaxValue == maxValue
469+ if let initialColor = initialColor? . cgColor, isInitial {
470+ minLabel. foregroundColor = initialColor
471+ maxLabel. foregroundColor = initialColor
472+ sliderLineBetweenHandles. backgroundColor = initialColor
473+ sliderLine. backgroundColor = initialColor
474+
475+ let color : CGColor = ( handleImage == nil ) ? initialColor : UIColor . clear. cgColor
476+ leftHandle. backgroundColor = color
477+ leftHandle. borderColor = color
478+ rightHandle. backgroundColor = color
479+ rightHandle. borderColor = color
480+ } else {
481+ let tintCGColor : CGColor = tintColor. cgColor
482+ minLabel. foregroundColor = minLabelColor? . cgColor ?? tintCGColor
483+ maxLabel. foregroundColor = maxLabelColor? . cgColor ?? tintCGColor
484+ sliderLineBetweenHandles. backgroundColor = colorBetweenHandles? . cgColor ?? tintCGColor
485+ sliderLine. backgroundColor = tintCGColor
486+
487+ let color : CGColor
488+ if let _ = handleImage {
489+ color = UIColor . clear. cgColor
490+ } else {
491+ color = handleColor? . cgColor ?? tintCGColor
492+ }
493+ leftHandle. backgroundColor = color
494+ leftHandle. borderColor = color
495+ rightHandle. backgroundColor = color
496+ rightHandle. borderColor = color
497+ }
498+ }
499+
544500 private func updateAccessibilityElements( ) {
545501 accessibleElements = [ leftHandleAccessibilityElement, rightHandleAccessibilityElement]
546502 }
@@ -639,6 +595,7 @@ import UIKit
639595 CATransaction . commit ( )
640596
641597 updateLabelValues ( )
598+ updateColors ( )
642599 updateAccessibilityElements ( )
643600
644601 // update the delegate
0 commit comments