2011-03-10 5 views
3

안녕하세요 여러분, UILlabels 텍스트로 UISliders 값을 표시하는 방법이 궁금합니다. 라벨 및/또는 슬라이더가 IB 요소 인 경우,UISliders 값으로 UILabels 텍스트 변경

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

IBOutlets를 정의하고 연결 : 감사

답변

8

는 다음과 같이, 슬라이더에 작업을 추가

[slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged]; 

sliderChanged: 방법을 이런 식으로 뭔가 보이는 경우 :

- (void)sliderChanged:(UISlider *)slider { 
    self.label.text = [NSString stringWithFormat:@"%g", slider.value]; 
} 
7

이보십시오.

그런 다음이 방법으로 슬라이더 sliderChanged을 연결하십시오.

행운을 빈다.

+0

매우 감사를! –

1
//This is for getting the Int Value 

- (IBAction)sliderValueChanged:(UISlider *)sender 
{ 
    yourtextlabel.text = [NSString stringWithFormat:@"%d", (int)yourslideroutletname.value]; 
NSLog(@"the selider value==%@",yourtextlabel.text); 
} 

//This is for getting the float Value 

- (IBAction)sliderValueChanged:(UISlider *)sender 
{ 
    yourtextlabel.text = [NSString stringWithFormat:@"%f", yourslideroutletname.value]; 
NSLog(@"the selider value==%@",yourtextlabel.text); 
} 
관련 문제