IOS UISlider non continuos approximate value

隐身守侯 提交于 2019-12-02 06:57:20

问题


I have a UISlider with value between 10 and 100. I works very well.

Except I'd like to be able to increase the values by 5 rather than 1 by 1.

Now, if I move the slide the values are increasing linear: 10, 11, 12, 13, ....

I want to be able when moving the slider the values to increase by 5: 10, 15, 20, 25, ....

Is this possible?

Many thanks!


回答1:


Here's some code for you, base on a stackoverflow post somewhere...

- (IBAction)terrainValueChanged:(id)sender {

    float newStep = roundf((terrainSlider.value) / self.stepValue);
    self.terrainSlider.value = newStep * self.stepValue;
    int intValue = self.terrainSlider.value;
    terrainRating = intValue;

}

Initialize with this:

    stepValue = 1;
    self.terrainStep = (self.terrainSlider.value) / self.terrainStep;



回答2:


use this code for increasing the slide value by 5

sliderPosition = (int)(round(mySlider.value/5)*5); 


来源:https://stackoverflow.com/questions/9161517/ios-uislider-non-continuos-approximate-value

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