about showing continuous slider value in UISlider

Ahsan picture Ahsan · Jun 5, 2011 · Viewed 10.7k times · Source

Here's what I want to do with UI Slider ....

I have a bunch of files with times and I show them based on slider value. The problem is I want to show the slider value when the user is changing/moving the slider. In other words, the value should change (and be shown on the screen) as the user is moving the slider (and not afterwards).

Can anyone please give me any idea how to do it ?

Thanks.

Answer

Chris Cooper picture Chris Cooper · Jun 5, 2011

You can ask to get a method called when the slider's value changes. Then using that change, you should update the text of a label.

To listen for the value's change:

[mySlider addTarget:self action:@selector(mySliderChanged:) forControlEvents:UIControlEventValueChanged];

Then to update the label:

NSString *labelString = [NSString stringWithFormat:@"Slider value is %d", mySlider.value];
[myLabel setText:labelString];