Skip to content

Commit

Permalink
Add Property, knobHighlightable to mimic the default UISlider.
Browse files Browse the repository at this point in the history
  • Loading branch information
why2pac committed Mar 3, 2017
1 parent c03ac9b commit c35ca45
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions SwiftRangeSlider/RangeSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ import QuartzCore
}
}

///Whether the knows are highlightable. `true` by default.
@IBInspectable open var knobHighlightable: Bool = true {
didSet {
upperKnob.highlightable = knobHighlightable
lowerKnob.highlightable = knobHighlightable
}
}

var previousLocation = CGPoint()
var previouslySelectedKnob = Knob.Neither

Expand Down Expand Up @@ -243,11 +251,13 @@ import QuartzCore

lowerKnob.frame = CGRect(x: 0, y: 0, width: KnobSize, height: KnobSize)
lowerKnob.rangeSlider = self
lowerKnob.highlightable = knobHighlightable
lowerKnob.contentsScale = UIScreen.main.scale
layer.addSublayer(lowerKnob)

upperKnob.frame = CGRect(x: 0, y: 0, width: KnobSize, height: KnobSize)
upperKnob.rangeSlider = self
upperKnob.highlightable = knobHighlightable
upperKnob.contentsScale = UIScreen.main.scale
layer.addSublayer(upperKnob)

Expand Down
4 changes: 3 additions & 1 deletion SwiftRangeSlider/RangeSliderKnob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ enum Knob {
}

class RangeSliderKnob: CALayer {
var highlightable: Bool = true

var highlighted: Bool = false {
didSet {
if let superLayer = superlayer, highlighted {
Expand Down Expand Up @@ -47,7 +49,7 @@ class RangeSliderKnob: CALayer {
ctx.addPath(knobPath.cgPath)
ctx.strokePath()

if highlighted {
if highlighted && highlightable {
ctx.setFillColor(UIColor(white: 0.0, alpha: 0.1).cgColor)
ctx.addPath(knobPath.cgPath)
ctx.fillPath()
Expand Down

0 comments on commit c35ca45

Please sign in to comment.