2013-06-12 37 views
0

正如您從我的代碼中可以看到的那樣,當我移動滑塊時,滑塊將改變.1 .1 .1 .1的文本字段值。意思是如果我稍微向右移一點,值可能是43.7。有沒有一種方法可以改變代碼,使其增加.5 .5 .5 5.所以,如果我移動它可以是43.5,44,44.5,45.這種事情。讓我知道你是否有疑問!謝謝你的幫助。Xcode Slider Value Change +.5

- (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

您的問題是,當你的代碼的七號線。您已將值設置爲上升並顯示一位小數的增量。試試這個:

billAmountTextField.text = [NSString stringWithFormat:@"%1.0f", value];