正如您从下面的代码中看到的那样,当我移动滑块时,滑块会将文本字段的值更改为 .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];
}
谢谢