A guide to the use of uistepper numerical subtraction converters in IOS _ios

Source: Internet
Author: User

Uistepper can continuously increase or decrease a value. The control's appearance is made up of two horizontal buttons, one shown as "+" and one shown as "-".
An interesting feature of this control is that when the user presses the "+", "-" button, the number of space values is changed by a different number depending on the length of time that is pressed. The longer you hold down, the faster the value changes. You can set a range of values for uistepper, such as 0-99. It shows the following effects:

1. Attribute Description
Value: The current representation, defaults to 0.0;
MinimumValue: The smallest can represent the value, the default 0.0;
MaximumValue: Maximum can represent the value, the default 100.0;
Stepvalue: Each increment or decrement of the value, the default is 1.0;

2. How to Judge Plus ("+") minus ("-")
(1) by setting up a double* previousvalue; *//* Used to record the last value of stepper.value*
(2) After the operation of the object to be manipulated, the Stepper.value = 0

Copy Code code as follows:

#pragma mark-Set Uistepper
-(void) createuistepper{

Uistepper * Stepperbutton = [[Uistepper alloc]initwithframe:cgrectmake (225, 500, 30, 10)];
[Stepperbutton addtarget:self Action: @selector (Controlsteppervalue:) forcontrolevents:uicontroleventvaluechanged] ;
Stepperbutton.maximumvalue = 100.0;
Stepperbutton.minimumvalue = 0.0;
Stepperbutton.value = Inituisteppervalue;
Stepperbutton.stepvalue = 1.0;
stepperbutton.continuous = YES;
Stepperbutton.wraps = NO;
Stepperbutton.autorepeat = YES;
[Self.view Addsubview:stepperbutton];
[Stepperbutton release];

}


Copy Code code as follows:

-(void) Controlsteppervalue: (Uistepper *) stepper{

if (_segment.selectedsegmentindex = = 0) {
if (Stepper.value > Previousvalue) {
CGRect redrect = _redview.frame;
RedRect.size.height + 5;
_redview.frame = Redrect;
} else {

            CGRect redrect = _redview.frame;
            RedRect.size.height-= 5;
            _redview.frame = redrect;
       }
        previousvalue = stepper.value;
   }else{
        if (Stepper.value > Previousvalue) {
            CGRect redrect = _greenview.frame;
            redRect.size.height + 5;
            _greenview.frame = redrect;
       } else {

CGRect redrect = _greenview.frame;
RedRect.size.height-= 5;
_greenview.frame = Redrect;
}
Previousvalue = Stepper.value;
}

}

3. Basic usage Finishing
Initializing controls

Copy Code code as follows:

Uistepper * step = [[Uistepper alloc]initwithframe:cgrectmake (100, 100, 100, 100)];

Set the controller value to trigger changes continuously
Copy Code code as follows:

@property (nonatomic,getter=iscontinuous) BOOL continuous;

If set to Yes, the long press will trigger the change continuously, if set to No, only after hitting the end, will trigger.
Set whether the long press has been triggering changes
Copy Code code as follows:

@property (nonatomic) BOOL autorepeat;

If set to Yes, the long by value will change all the time, if set to No, then one click will only change the value once
Set the controller's value to loop (after reaching the boundary, start again, default is NO)
Copy Code code as follows:

@property (nonatomic) BOOL wraps;

Set the value of the controller
Copy Code code as follows:

@property (nonatomic) Double value;

Set the maximum and minimum controller values
Copy Code code as follows:

@property (nonatomic) Double minimumvalue;//defaults to 0
@property (nonatomic) double maximumvalue; Default is 100

To set the controller's step size
Copy Code code as follows:

@property (nonatomic) double stepvalue;

Set the controller style color
Copy Code code as follows:

@property (Nonatomic,retain) Uicolor *tintcolor;

Set controller background picture
Copy Code code as follows:

-(void) SetBackgroundImage: (uiimage*) Image forstate: (uicontrolstate) state;

Get background picture
Copy Code code as follows:

-(uiimage*) Backgroundimageforstate: (uicontrolstate) state;

To set a picture of a split line by the left and right button's state
Copy Code code as follows:

-(void) Setdividerimage: (uiimage*) Image forleftsegmentstate: (uicontrolstate) leftstate rightsegmentstate: ( Uicontrolstate) Rightstate;

Get a picture of a split line
Copy Code code as follows:

-(uiimage*) Dividerimageforleftsegmentstate: (uicontrolstate) State rightsegmentstate: (uicontrolstate) state;

To set and get a picture of the plus button
Copy Code code as follows:

-(void) Setincrementimage: (UIImage *) image forstate: (uicontrolstate) state;
-(UIImage *) Incrementimageforstate: (uicontrolstate) state;

To set and get a picture of the minus button
Copy Code code as follows:

-(void) Setdecrementimage: (UIImage *) image forstate: (uicontrolstate) state;
-(UIImage *) Decrementimageforstate: (uicontrolstate) state;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.