Thumb image does not move to the edge even when it\'s value is max or min.
Does anyone know how to make it move all the way to the edge of the slider?
Most upvoted answer didn't work for me without changes. Here's what did -- it's a drop in replacement for UISlider
:
class Slider: UISlider {
override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float)->CGRect {
var thumbRect = super.thumbRect(forBounds: bounds, trackRect: rect, value: value)
//determine value dependent offset
var offsetForValue: CGFloat = 0
if value != 0 {offsetForValue = thumbRect.size.width * CGFloat(value / (self.maximumValue - self.minimumValue)) - ((value > 0) ? 2 : -2)}
//apply offset to thumb rect
thumbRect.origin.x += offsetForValue
return thumbRect
}
}