Implementing steps/snapping UISlider

后端 未结 6 1078
悲哀的现实
悲哀的现实 2020-12-23 02:07

I am trying to implement some form of snapping or steps with the UISlider. I have written the following code but it does not work as smooth as I hoped for. It works, but whe

6条回答
  •  情话喂你
    2020-12-23 02:34

    A really simple one:

    - (void)sliderUpdated:(UISlider*)sli {
        CGFloat steps = 5;
        sli.value = roundf(sli.value/sli.maximumValue*steps)*sli.maximumValue/steps;    
    }
    

    Great if you want a fast solution and you've added the target by UIControlEventValueChanged.

提交回复
热议问题