2013-06-12 2 views
0

아래 코드에서 볼 수 있듯이 슬라이더를 이동하면 슬라이더가 텍스트 필드의 값을 .1 .1 .1 .1로 변경합니다. 오른쪽으로 조금 움직이면 값은 43.7이 될 수 있습니다. 5.5.5를 추가하는 코드를 변경할 수있는 방법이 있습니까? 5. 이동하면 43.5, 44, 44.5, 45가 될 수 있습니다. 그런 종류의 것입니다. 질문이 있으면 알려주세요. 당신의 도움을 주셔서 감사합니다.Xcode 슬라이더 값 변경 +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

당신의 문제는 때 코드의 7 라인. 값을 설정하여 소수점 한 자리 증가분을 표시합니다. 사용해보기 :

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