IOS basic 2: Use of UIStepper (Counter)

Source: Internet
Author: User

IOS basic 2: Use of UIStepper (Counter)
This is a control that appears only after iOS5. It has been used in projects. Therefore, UIStepper is a control similar to UISwitch, but there is a plus sign and a minus sign on both sides of the control.The control looks similar to UISwitch and consists of two buttons. A button is "+" and a button is "-" to jointly control the increase or decrease of the same value.
In iOS5, a digital input control UIStepper is added, which can be used to incrementally input the number. UIStepper inherits from UIControl. Its main event is UIControlEventValueChanged. This event is triggered whenever its value changes.

It mainly has the following attributes:

    The value currently expressed. The default value is 0.0 minimumValue. The default value is 0.0. The default value is 100.0, by default, some attributes and methods in the 1.0 document are as follows: Configure Stepper
    • continuous AttributeBOOL type. The default value is YES. YES indicates that the ValueChange event will be sent immediately when the user interaction ends. NO indicates that the ValueChange event will be sent only when the user interaction ends.
    • autorepeat AttributeBOOL type. The default value is YES. If YES, it means to press and hold the plus sign or minus sign to keep changing the number.
    • wraps AttributeBOOL type. The default value is NO. If YES, when the value is greater than maximumValue, the value is changed to the value of minimumValue. If the value is smaller than minimumValue, the value is changed to the value of maximum. If it is set to NO, the value will not exceed the maximum and minimum values.
    • minimumValue AttributeDouble TypeThe default value is 0 and the minimum value. If the value is greater than or equal to maximumValue, an NSInvalidArgumentExcepti message is returned.On exception
    • maximumValue AttributeDouble TypeThe default value is 100, which is the maximum value of Stepper. If it is set to be smaller than or equal to minimumValue,NSInvalidArgumentExceptiOn exception
    • stepValue AttributeThe default value of the Double type is 1, and the increment or number of steps of Stepper (for example, if stepValue is 10, add 10 at the click, and then subtract 10). The value must be greater than 0. Otherwise,NSInvalidArgumentExceptiOn exception
    • Access Stepper Value
    • value AttributeThe default value of the Double type is 0, and the maximum value is maximumValue and the minimum value is minimumValue. When the value changes, the UIControlValueEventChangEd to target
    • Customized appearance
    • tintColor Attribute UIColor type. The default value is nil. It is added in iOS 6.
      • -(UIImage*) BackgroundImageForState :( UIControlState) state
      • What status do I use for background images? added in iOS 6
      • UIControlState has six enumerated Variables
        
              
              
        • enum {
        
              
              
        • UIControlStateNormal = 0, normal
          • UIControlStateHighlighteD = 1 <0, click within the scope, but it is not easy
            • UIControlStateDisabled = 1 <1, when disabled
              • UIControlStateSelected = 1 <2, click it, and the loose is usually the status in which the button is pressed and sunken.
                • UIControlStateApplicatioN = 0x00FF0000, additional status when used by the application
                  • UIControlStateReserved = 0xFF000000 internal framework used
                    • };
      • -(Void) setBackgroundImage :( UIImage*) ImageForState :( UIControlState) state
      • The best picture is scalableNew in iOS 6

      • -(UIImage*) DecrementImageForState :( UIControlState) state
      • New in iOS 6
      • -(Void) setDecrementImage :( UIImage*) ImageForState :( UIControlState) state
      • New in iOS 6
      • Image of The minus sign button

      • -(UIImage*) IncrementImageForState :( UIControlState) state
      • New in iOS 6
      • -(Void) setIncrementImage :( UIImage*) ImageForState :( UIControlState) state
      • New in iOS 6
      • Image with the plus sign

      • -(UIImage*) DividerImageForLeftSegmeNtState :( UIControlState) leftStateRightSegmentState :( UIControlState) rightState
      • LeftState is the status of the button on the left, and rightState is the status of the button on the right.
      • Change the widget image when two buttons are in different States.
      • -(Void) setDividerImage :( UIImage*) ImageForLeftSegmentState :( UIControlState) leftStateRightSegmentState :( UIControlState) rightState
      • New in iOS 6
        Example: testStepper. stepValue = 10; testStepper. minimumValue = 0; testStepper. maximumValue = 55; testStepper. value = 10; testStepper. tintColor = [UIColor redColor]; testStepper. wraps = YES; it is always added at the beginning, then the value changes to 20 30 40 50 55 it is always reduced at the beginning, then the value changes to 0When the upper or lower limit is reached and wraps is not set to YES, the corresponding plus or minus button will be disable

        An interesting feature of this control is that when you press the "+" "-" button, the number of the control value is changed according to the length of the hold-down time. The longer the hold-down time, the faster the value changes. You can set a value range for UIStepper, for example, 0-99.

        The following is the UIStepper application sample code:

        01 // Create a label to show the value in the stepper
        02 label = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 100, 30)];
        03 [label setTextColor:[UIColor whiteColor]];
        04 [label setBackgroundColor:[UIColor clearColor]];
        05 [label setTextAlignment:UITextAlignmentLeft];
        06 [label setText: @"Quantity:"];
        07 [[self view] addSubview:label];
        08
        09 // Frame defines location, size values are ignored
        10 UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(120, 20, 0, 0)];
        11
        12 // Set action target and action for a particular value changed event
        13 [stepper addTarget:self action:@selector(stepperPressed:) forControlEvents:UIControlEventValueChanged];
        14
        15 // Set min and max
        16 [stepper setMinimumValue:0];
        17 [stepper setMaximumValue:99];
        18
        19 // Value wraps around from minimum to maximum
        20 [stepper setWraps:YES];
        21
        22 // If continuos (default), changes are sent for each change in stepper,
        23 // otherwise, change event occurs once user lets up on button
        24 [stepper setContinuous:NO];
        25
        26 // To change the increment value for each step
        27 // (default is 1)
        28 [stepper setStepValue:10];


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.