0

正如您从下面的代码中看到的那样,当我移动滑块时,滑块会将文本字段的值更改为 .1 .1 .1 .1。这意味着如果我向右移动一点,值可能是 43.7。有没有办法我可以更改代码以使其添加 .5 .5 .5 5。所以如果我移动它可能是 43.5、44、44.5、45。那种事情。如果您有任何问题,请告诉我!谢谢你的帮助。

- (IBAction) sliderValueChanged:(UISlider *)sender {
billAmountTextField.text = [NSString stringWithFormat:@" %.1f", [sender value]];

}

- (IBAction) changeButtonPressed:(id)sender {
NSString *textValue = [billAmountTextField text];
float value = [textValue floatValue];
if (value < 0) value = 0;
if (value > 100) value = 100;
mySlider.value = value;
billAmountTextField.text = [NSString stringWithFormat:@"%.1f", value];
if ([billAmountTextField canResignFirstResponder]) [billAmountTextField resignFirstResponder];

}

- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event {
if (billAmountTextField) {
    if ([billAmountTextField canResignFirstResponder]) [billAmountTextField resignFirstResponder];
}
[super touchesBegan: touches withEvent: event];

}

谢谢

4

1 回答 1

0

您的问题是代码的第 7 行。您已将值设置为增加并显示小数点后一位。尝试这个:

billAmountTextField.text = [NSString stringWithFormat:@"%1.0f", value];
于 2014-05-30T02:47:11.313 回答