How to make UISlider output nice rounded numbers exponentially?
- by RickiG
Hi
I am implementing a UISlider a user can manipulate to set a distance.
I have never used the CocoaTouch UISlider, but have used other frameworks sliders, usually there is a variable for setting the "step" and other "helper" properties.
The documentation for the UISlider deals only with a max and min value, and the output is always a 6 decimal float with a linear relation to the position of the "slider nob". I guess I will have to implement the desired functionality step by step.
To the user, the min/max values range from 10 m to 999 Km, I am trying to implement this in an exponential way, that will feel natural to the user. I.e. the user experiences a feeling of control over the values, big or small. Also that the "output" has reasonable values. Values like 10m 200m 2.5km 150 km etc. instead of 1.2342356 m or 108.93837756 km.
I would like for the step size to increase by 10m for the first 200m, then maybe by 50m up to 500m, then when passing the 1000 m value, it starts to deal with Kilometers, so then it is step size = 1 km up until 50 km, then maybe 25 km steps etc.
Any way I go about this I end up doing a lot of rounding and a lot of calculations wrapped in
a forrest of if statements and NSString/Number conversions, each time the user moves the slider just a little.
I was hoping someone could lend me a bit of inspiration/math help or make me aware of
a more lean approach to solving this problem.
My last idea is to populate and array with a 100 string values, then have the slider int value correspond to a string, this is not very flexible, but doable.
Thank you in advance for any help given:)