Stop UISlider at Value

不羁的心 提交于 2019-12-04 05:25:06

问题


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:


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



来源:https://stackoverflow.com/questions/7950577/stop-uislider-at-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!