Skip to content

Commit ca40719

Browse files
committed
Use the view's tint color for the color of the slider thumb
1 parent cf6842a commit ca40719

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

Example/TactileSlider/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ViewController: UIViewController {
1818
if #available(iOS 13, *) {
1919
self.view.backgroundColor = UIColor.systemBackground
2020
} else {
21-
self.view.backgroundColor = UIColor.lightGray
21+
self.view.backgroundColor = UIColor.white
2222
}
2323
}
2424

TactileSlider/Classes/TactileSlider.swift

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,34 +86,19 @@ import UIKit
8686

8787
/// The color of the track the slider slides along
8888
///
89-
/// - Important: This defaults to the dynamic system fill color on iOS 13 or greater, but to darkGray on older versions
89+
/// - Important: This defaults to the dynamic system fill color on iOS 13 or greater, but to lightGray on older versions
9090
@IBInspectable open var trackBackground: UIColor = {
9191
if #available(iOS 13, *) {
9292
return .systemFill
9393
} else {
94-
return .darkGray
94+
return .lightGray
9595
}
9696
}() {
9797
didSet {
9898
renderer.trackBackground = trackBackground
9999
}
100100
}
101101

102-
/// The color of the value indicator part of the slider
103-
///
104-
/// - Important: This defaults to a dynamic system color on iOS 13 or greater, but to white on older versions
105-
@IBInspectable open var thumbTint: UIColor = {
106-
if #available(iOS 13, *) {
107-
return .label
108-
} else {
109-
return .white
110-
}
111-
}() {
112-
didSet {
113-
renderer.thumbTint = thumbTint
114-
}
115-
}
116-
117102
/// The radius of the rounded corners of the slider
118103
///
119104
/// Note: If this is set to a negative value (or left as default in interface builder), the corner radius will be automatically determined from the size of the bounds
@@ -214,8 +199,7 @@ import UIKit
214199

215200
renderer.tactileSlider = self
216201
renderer.cornerRadius = cornerRadius
217-
renderer.trackBackground = trackBackground
218-
renderer.thumbTint = thumbTint
202+
traitCollectionDidChange(nil)
219203

220204
layer.backgroundColor = UIColor.clear.cgColor
221205
layer.isOpaque = false
@@ -346,7 +330,11 @@ import UIKit
346330

347331
open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
348332
renderer.trackBackground = trackBackground
349-
renderer.thumbTint = thumbTint
333+
tintColorDidChange()
334+
}
335+
336+
open override func tintColorDidChange() {
337+
renderer.thumbTint = tintColor
350338
}
351339

352340
override open func layoutSubviews() {

0 commit comments

Comments
 (0)