Stop UISlider at Value

2019-03-02 05:30发布

I have a UISlider and I want it to stop at a certain value. This is not the maximum, but a number that is available programmatically.

Example: UISlider has max value of 100. The stop value is 60. Therefore, the user shouldn't be able to drag beyond 60.

The method I'm using right now is to add an action with a selector function, and there I would change the value back to the stopped position.

[mySlider addTarget:self action:@selector(modifySliderValue) forControlEvents:UIControlEventValueChanged];

...

- (void)modifySliderValue{
    if(mySlider.value > 60) {
        mySlider.value = 60;
    }
}

This doesn't work well as the slider appears glitchy. It keeps trying to skip past the 60 mark and it doesn't look right.

What is the best way to achieve this?

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-03-02 05:41

I found an easy solution by using UIControlEventAllEvents instead of UIControlEventValueChanged.

查看更多
登录 后发表回答