有没有办法让iPhone应用程序中UISlider输出的值呈指数级增长?例如,第一个生成1 -10,第二个生成11到100,最后一个生成101到1000?
答案 0 :(得分:12)
您可以从滑块计算自己的log / exp值,并显示该值!
但是如果你想要一个介于1到1000之间的值,你可以将滑块的min设置为0,max设置为3并使功率为10:
powf(10.0,mySlider.value)
答案 1 :(得分:11)
我从这篇文章中导出了这些Objective C方法: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);
}