嘿伙计们,我想知道如何将UISliders值显示为UILabels文本。感谢
答案 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);
}