UIStepper can continuously increase or decrease a value. The appearance of the control is composed of two horizontally side by side buttons, one displayed as "+" and the other displayed as "-".
An interesting feature of this control is that when the user holds the "+" and "-" buttons, the number of space values also changes with different numbers depending on the length of time it is held. The longer the time you hold it, the faster the value changes. You can set a numerical range for UIStepper, such as 0-99. Its display effect is as follows:
1. Attribute description
value: The value currently represented, default is 0.0;
minimumValue: The minimum value that can be represented, default 0.0;
maximumValue: The maximum value that can be represented, default is 100.0;
stepValue: The value of each increment or decrement, default is 1.0;
2. How to judge whether to add ("+") or subtract ("-")
(1) Set a double* previousValue; *// * to record the last value of *
(2) After operating the object you want to operate, turn = 0
#pragma mark - Set UIStepper
- (void)createUIStepper{
UIStepper * stepperButton = [[UIStepper alloc]initWithFrame:CGRectMake(225, 500, 30, 10)];
[stepperButton addTarget:self action:@selector(controlStepperValue:) forControlEvents:UIControlEventValueChanged];
= 100.0;
= 0.0;
= INITUISTEPPERVALUE;
= 1.0;
= YES;
= NO;
= YES;
[ addSubview:stepperButton];
[stepperButton release];
}
- (void)controlStepperValue:(UIStepper *)stepper{
if (_segment.selectedSegmentIndex == 0) {
if ( > previousValue) {
CGRect redRect = _redView.frame;
+= 5;
_redView.frame = redRect;
} else {
CGRect redRect = _redView.frame;
-= 5;
_redView.frame = redRect;
}
previousValue = ;
}else{
if ( > previousValue) {
CGRect redRect = _greenView.frame;
+= 5;
_greenView.frame = redRect;
} else {
CGRect redRect = _greenView.frame;
-= 5;
_greenView.frame = redRect;
}
previousValue = ;
}
}
3. Basic usage sorting
Initialize the control
UIStepper * step = [[UIStepper alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
Set whether the controller value triggers changes continuously
@property(nonatomic,getter=isContinuous) BOOL continuous;
If set to YES, long pressing will trigger changes continuously. If set to NO, it will only be triggered after the press is finished.
Set whether long presses and changes are triggered
@property(nonatomic) BOOL autorepeat;
If set to YES, the long pressing value will change continuously. If set to NO, the value will only be changed once a click.
Set whether the controller's value is cyclic (after reaching the boundary, start over, default is NO)
@property(nonatomic) BOOL wraps;
Set the value of the controller
@property(nonatomic) double value;
Set the maximum and minimum values of the controller
@property(nonatomic) double minimumValue;//Default is 0
@property(nonatomic) double maximumValue; //Default is 100
Set the step size of the controller
@property(nonatomic) double stepValue;
Set controller style color
@property(nonatomic,retain) UIColor *tintColor;
Set controller background picture
- (void)setBackgroundImage:(UIImage*)image forState:(UIControlState)state;
Get background image
- (UIImage*)backgroundImageForState:(UIControlState)state;
Pictures of setting the split line through the status of left and right buttons
- (void)setDividerImage:(UIImage*)image forLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState;
Get the split line picture
- (UIImage*)dividerImageForLeftSegmentState:(UIControlState)state rightSegmentState:(UIControlState)state;
Set and get pictures of plus buttons
- (void)setIncrementImage:(UIImage *)image forState:(UIControlState)state;
- (UIImage *)incrementImageForState:(UIControlState)state;
Setting and getting pictures of minus buttons
- (void)setDecrementImage:(UIImage *)image forState:(UIControlState)state;
- (UIImage *)decrementImageForState:(UIControlState)state;