我有一个最小的UISlider - 0.1& max - 1.我希望显示值的标签显示小数而不只是0和1。
以下是当前代码:
- (IBAction)sliderChange:(UISlider *)sender { // When the slider for the power factor is moved
sender.minimumValue = 0.1;
sender.maximumValue = 1.0;
int progress = lround(sender.value);
self.sliderLabel.text = [NSString stringWithFormat:@"%d", progress];
}
如果有人可以提供帮助,我会非常感激。
答案 0 :(得分:0)
两件事:你的progress
变量是一个int。将其更改为CGFloat
。
接下来,尝试使用
[NSString stringWithFormat:@"%f", progress]
代替(注意%f
而不是%d
)。 %f
用于浮点值,%d
用于整数。