Is there a way to got the values outputted by a UISlider in an iPhone app to increase exponentially? For example the first third generate 1 -10, the second third generate 11 to 100, and the final third generate 101 to 1000?
Asked
Active
Viewed 5,360 times
6
-
That sounds more like exponential than logarithmic... – Vladimir Nov 05 '10 at 11:48
-
i wasn't sure it was the right word but wikipedia says "A simple example is when increments on the vertical axis of a chart are labeled 1, 10, 100, 1000, instead of 1, 2, 3, 4." – lavelle Nov 05 '10 at 11:53
2 Answers
14
You can compute yourself the log/exp value from the slider, and display this value !
But if you want a value between 1 to 1000, you can set min of the slider to 0, max to 3 and make the power of 10:
powf(10.0,mySlider.value)

Benoît
- 7,395
- 2
- 25
- 30
-
haha kinda genius, didn't think of that :P what's the obj-c code for this? is there a function or do i write the math myself? use if statements to determine how much to multiply each value by, or is there a cleaner way? – lavelle Nov 05 '10 at 11:54
-
That is the function, in C. Wherever you want to retrieve the slider value as exponential, use that snippet there. Don't forget to mark Benôit's answer as accepted. – fearmint Nov 05 '10 at 12:01
-
Note: For 0->1 log10 you should do something like `((10^x)-1)/9`. I found with volume for example, a sliderValue from 0.0 to 1.0 correlates best with log base 100: `float volumeLevel = (powf(100.0f, sliderValue)-1.0f)/99.0f;` – Albert Renshaw Dec 25 '18 at 22:13
13
I derived these Objective C methods from this post: Logarithmic slider
-(double) wpmForSliderValue: (double) sliderValue {
// Input will be between min and max
static double min = WPM_SLIDER_MIN;
static double max = WPM_SLIDER_MAX;
// Output will be between minv and maxv
double minv = log(WPM_SCALE_MIN);
double maxv = log(WPM_SCALE_MAX);
// Adjustment factor
double scale = (maxv - minv) / (max - min);
return exp(minv + (scale * (sliderValue - min)));
}
-(double) sliderValueForWpm: (double) wpm {
// Output will be between min and max
static double min = WPM_SLIDER_MIN;
static double max = WPM_SLIDER_MAX;
// Input will be between minv and maxv
double minv = log(WPM_SCALE_MIN);
double maxv = log(WPM_SCALE_MAX);
// Adjustment factor
double scale = (maxv - minv) / (max - min);
return (((log(wpm) - minv) / scale) + min);
}

Community
- 1
- 1

Adam Talaat
- 131
- 1
- 2
-
I needed to work out how to adjust an aspect ratio from something arbitrary down to 1:1 based on a value of 1.0-.0.5, this code was the basis for my solution. Thank you! – Will Jones Mar 06 '19 at 11:58
-