如何设置0.5间隔的uislider值

时间:2015-10-01 07:53:33

标签: ios objective-c uislider

拥有最小值5和最大值10的UISLider如何在uilabel中显示0.5区间的值范围

_ie.text = [NSString stringWithFormat:@"%0.1f",(_Iel.value)];

2 个答案:

答案 0 :(得分:3)

你可以像这样圆:

_ie.text = [NSString stringWithFormat:@"%0.1f",(roundf(_Iel.value * 2.0) * 0.5)];

答案 1 :(得分:0)

这适用于0.5或任何其他间隔

- (IBAction)sliderValueChanged:(id)sender
{
    self.increment = 0.5f;
    float roundedSliderValue = roundf(self.theSlider.value / self.increment) * self.increment;
    _ie.text = [NSString stringWithFormat:@"%0.1f",roundedSliderValue];
}