Search code examples
swiftpositionuislideruiprogressview

How to set UISlider's value not to extend over UIProgressBar's progress


I have a UISlider and UIProgressView embedded together and I want to get the position of the progress tint of progress view and stop slider to slide before the progress tint. How to get the position of UIProgressView and clip the UISlider to the bound of progress on UIProgressView?


Solution

  • Instead trying to use the above method, we can also obtain the same default behaviours from UISlider by disabling the userInteraction of the slider as:

    slider_name.userInteractionEnabled = false

    We could than set the UISlider's thumb image, which will stick to the current value you assign.

    slider_name.setThumbImage(UIImage(named: "image_name"), forState: .Normal)