about showing continuous slider value in UISlider

2019-03-27 07:00发布

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.

标签: ios uislider
2条回答
一纸荒年 Trace。
2楼-- · 2019-03-27 07:35

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.

查看更多
等我变得足够好
3楼-- · 2019-03-27 07:54

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];
查看更多
登录 后发表回答