IOS UISlider non continuos approximate value

后端 未结 2 832
忘了有多久
忘了有多久 2021-01-22 16:49

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 th

2条回答
  •  北海茫月
    2021-01-22 17:18

    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;
    

提交回复
热议问题