Skip to content

Commit

Permalink
Set the view's tintAdjustmentMode when disabled rather than computi…
Browse files Browse the repository at this point in the history
…ng a custom dimmed tint color
  • Loading branch information
daprice committed May 2, 2020
1 parent 4a10895 commit bf24553
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
1 change: 1 addition & 0 deletions TactileSlider/Classes/TactileSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ import UIKit
override open var isEnabled: Bool {
didSet {
renderer.grayedOut = !isEnabled
tintAdjustmentMode = isEnabled ? .automatic : .dimmed
}
}

Expand Down
17 changes: 1 addition & 16 deletions TactileSlider/Classes/TactileSliderLayerRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,10 @@ internal class TactileSliderLayerRenderer {

var thumbTint: UIColor = .white {
didSet {
thumbLayer.fillColor = grayedOut ? disabledThumbTint.cgColor : thumbTint.cgColor
thumbLayer.fillColor = thumbTint.cgColor
}
}

private var disabledThumbTint: UIColor {
// get HSV from normal tint color
var tintHue: CGFloat = 0
var tintSaturation: CGFloat = 0
var tintBrightness: CGFloat = 0
var tintAlpha: CGFloat = 0
guard thumbTint.getHue(&tintHue, saturation: &tintSaturation, brightness: &tintBrightness, alpha: &tintAlpha) else {
return UIColor.gray
}

return UIColor(hue: tintHue, saturation: tintSaturation/10, brightness: tintBrightness*0.8, alpha: tintAlpha*0.6)
}

var cornerRadius: CGFloat = 10 {
didSet {
updateMaskLayerPath()
Expand Down Expand Up @@ -92,8 +79,6 @@ internal class TactileSliderLayerRenderer {
private func updateGrayedOut() {
let alpha: Float = grayedOut ? 0.6 : 1
trackLayer.opacity = alpha

thumbLayer.fillColor = grayedOut ? disabledThumbTint.cgColor : thumbTint.cgColor
}

private func updatePopUp() {
Expand Down

0 comments on commit bf24553

Please sign in to comment.