正如您在下面的代码中看到的,当我移动滑块时,滑块会将文本字段的值更改为.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];
}
由于
答案 0 :(得分:0)
你的问题是代码的第7行。您已将值设置为上升并显示一位小数的增量。试试这个:
billAmountTextField.text = [NSString stringWithFormat:@"%1.0f", value];