about showing continuous slider value in UISlider

2019-03-27 07:16发布

问题:

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.

回答1:

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];


回答2:

UISlider class docs

mySlider.continuous = YES;


@property(nonatomic, getter=isContinuous) BOOL continuous

from docs:

Discussion

If YES, the slider sends update events continuously to the associated target’s action method. If NO, the slider only sends an action event when the user releases the slider’s thumb control to set the final value.



标签: ios uislider