使用UISliders值更改UILabels文本

时间:2011-03-10 03:18:08

标签: cocoa-touch ios uilabel uislider

嘿伙计们,我想知道如何将UISliders值显示为UILabels文本。感谢

3 个答案:

答案 0 :(得分:8)

向滑块添加操作,如下所示:

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

sliderChanged:方法看起来像这样:

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

答案 1 :(得分:7)

试试这个:

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

如果标签和/或滑块是IB元素,请定义IBOutlets并连接它们。

然后将滑块sliderChanged操作连接到此方法。

祝你好运!

答案 2 :(得分: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);
 }