UISlider with increments of 5

后端 未结 6 1176
离开以前
离开以前 2020-11-29 01:16

How do I have my UISlider go from 1-100 in increments of 5?

6条回答
  •  囚心锁ツ
    2020-11-29 01:41

    There is another way to active the stepper functionality. works in a general case

    Example:

    range of data is 0 - 2800 and I want the increments to be in 25 unit values. I would do the following

    1. set up the range of the slider to be 0 - (maxRange/unitsteps).
    2. when the value changed method runs use (int)slider.value * unitsteps .

    in the example above my slider would be set in IB to range 0 - 112. and my code would be (int)slider.value * 25.

    if you then have a text field that can be modified for direct input you would just do the opposite set the slider value to the [textfield.text intValue]/ unitsteps.

提交回复
热议问题