开发者

Use UISider to generate a logarithmic scale of values

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?


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)


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜