Introduction to UISlider
UISlider is a progress bar control, which controls the change of the value by sliding open. It is generally used in some playback progress, value adjustment, etc. The use of this control in development is not very much, and it is commonly used in some financial systems and audio and video app s.
UISlider properties
@property(nonatomic) float value; // default 0.0. this value will be pinned to min/max
@property(nonatomic) float minimumValue; // default 0.0. the current value may change if outside new min value
@property(nonatomic) float maximumValue; // default 1.0. the current value may change if outside new max value
@property(nonatomic,getter=isContinuous) BOOL continuous; // if set, value change events are generated any time the value changes due to dragging. default = YES
The above four attributes are the most commonly used attributes of UISlider
1. The value property sets the progress default value
2. The minimumValue property sets the minimum progress value
3. The maximumValue property sets the maximum progress value
4. The continuous property sets the response mechanism and determines the value only when the finger is released.
//Progress minimum
slider.minimumValue = 0.0;
//Progress maximum
slider.maximumValue = 100.0;
//Start default
slider.value = 22.0;
//Response setting mechanism. When you let go, the value is determined
slider.continuous = NO;
//Set background color
slider.backgroundColor =[UIColor redColor];
@property(nullable, nonatomic,strong) UIImage *minimumValueImage; // default is nil. image that appears to left of control (e.g. speaker off)
@property(nullable, nonatomic,strong) UIImage *maximumValueImage; // default is nil. image that appears to right of control (e.g. speaker max)
The two properties minimumValueImage and maximumValueImage are the pictures corresponding to the minimum and maximum values, as shown in the following figure:
//Set minimum picture
slider.minimumValueImage = [UIImage imageNamed:@"min.png"];
//Set maximum picture
slider.maximumValueImage = [UIImage imageNamed:@"max.png"];
UISlider listening event
The interaction response listening of the UISlider is the same as the response of the button. It is to add an event listening, which is controlled by the listening method.
//Add listening event
[slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
To achieve the desired effect in the sliderValueChanged: method.
Note: in the listening event, you are listening for the change of slider value.