A UISlider is a control that allows the user to select a value from a range of values horizontally by dragging the thumb to the position desired. Some use cases where a UISlider is used: Changing the Volume. Changing the Brightness. Changing the current seek of the Video.
If you try to programmatically set a slider's current value to be below the minimum or above the maximum, it's set to the minimum or maximum instead. However, if you set the value beyond the range of the minimum or maximum in Interface Builder, the minimum or minimum values are updated instead.
In IB, you can hook up an IBAction
to the Value Changed event
or in code add target/action for UIControlEventValueChanged
. For example:
[mySlider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
- (IBAction)sliderValueChanged:(UISlider *)sender {
NSLog(@"slider value = %f", sender.value);
}
Note that if you want the value change events as the user is sliding
, then be sure that the slider
's continuous property
is also set. On the other hand, if you don't want the event to fire as the user is sliding
and only when they finish sliding, set continuous to NO (or uncheck in IB).
For Swift 3
//There is your slider
@IBOutlet weak var mSlider: UISlider!
//add a target on your slider on your viewDidLoad for example
self.mSlider.addTarget(self, action: #selector(MyClass.onLuminosityChange), for: UIControlEvents.valueChanged)
//callback called when value change
func onLuminosityChange(){
let value = self.mSlider.value
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With