Monday, 26 August 2013

Introduction to UIStepper

Why we are using UIStepper  ??



Provides a user interface for incrementing or decrementing a value.




                                          Output of example code are shown in below image






Programmatically implement UIStepper


@interface ViewController ()
{
    UIStepper *steperCode;
}
@end

- (void)viewDidLoad
{
    [super viewDidLoad];
    steperCode = [[UIStepper alloc] initWithFrame:CGRectMake(140, 60, 300, 200)];
    [steperCode addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
    steperCode.maximumValue = 10;
    steperCode.minimumValue = 0;
    steperCode.stepValue=2.0;
    [self.view addSubview:steperCode];
}

- (IBAction)valueChanged:(UIStepper *)sender {
    double value = [sender value];
    
    [label setText:[NSString stringWithFormat:@"%d", (int)value]];
}


Here am using one more UILabel called "label"  for displaying stepper values (incremented values).








Below contents are from Apple Docs


Overview

A stepper control provides a user interface for incrementing or decrementing a value.
A stepper displays two buttons, one with a minus (“–”) symbol and one with a plus (“+”) symbol. The bounding rectangle for a stepper matches that of a UISwitch object.
If you set stepper behavior to “autorepeat” (which is the default), pressing and holding one of its buttons increments or decrements the stepper’s value repeatedly. The rate of change depends on how long the user continues pressing the control.
For information about basic view behaviors, see View Programming Guide for iOS.

Properties

autorepeat

The automatic vs. nonautomatic repeat state of the stepper.
@property(nonatomic) BOOL autorepeat
Discussion
If YES, the user pressing and holding on the stepper repeatedly alters value.
The default value for this property is YES.
Availability
  • Available in iOS 5.0 and later.
Declared In
UIStepper.h

continuous

The continuous vs. noncontinuous state of the stepper.
@property(nonatomic, getter=isContinuous) BOOL continuous
Discussion
If YES, value change events are sent immediately when the value changes during user interaction. If NO, a value change event is sent when user interaction ends.
The default value for this property is YES.
Availability
  • Available in iOS 5.0 and later.
Declared In
UIStepper.h

maximumValue

The highest possible numeric value for the stepper.
@property(nonatomic) double maximumValue
Discussion
Must be numerically greater than minimumValue. If you attempt to set a value equal to or lower than minimumValue, the system raises an NSInvalidArgumentException exception.
The default value of this property is 100.
Availability
  • Available in iOS 5.0 and later.
Declared In
UIStepper.h

minimumValue

The lowest possible numeric value for the stepper.
@property(nonatomic) double minimumValue
Discussion
Must be numerically less than maximumValue. If you attempt to set a value equal to or greater than maximumValue, the system raises an NSInvalidArgumentException exception.
The default value for this property is 0.
Availability
  • Available in iOS 5.0 and later.
Declared In
UIStepper.h

stepValue

The step, or increment, value for the stepper.
@property(nonatomic) double stepValue
Discussion
Must be numerically greater than 0. If you attempt to set this property’s value to 0 or to a negative number, the system raises an NSInvalidArgumentException exception.
The default value for this property is 1.
Availability
  • Available in iOS 5.0 and later.
Declared In
UIStepper.h

tintColor

The tint color for the stepper control.
@property(nonatomic, retain) UIColor *tintColor
Discussion
The value of this property is nil by default.
Availability
  • Available in iOS 6.0 and later.
Declared In
UIStepper.h

value

The numeric value of the stepper.
@property(nonatomic) double value
Discussion
When the value changes, the stepper sends the UIControlEventValueChanged flag to its target (see addTarget:action:forControlEvents:). Refer to the description of the continuous property for information about whether value change events are sent continuously or when user interaction ends.
The default value for this property is 0. This property is clamped at its lower extreme to minimumValue and is clamped at its upper extreme to maximumValue.
Availability
  • Available in iOS 5.0 and later.
Related Sample Code
Declared In
UIStepper.h

wraps

The wrap vs. no-wrap state of the stepper.
@property(nonatomic) BOOL wraps
Discussion
If YES, incrementing beyond maximumValue sets value to minimumValue; likewise, decrementing below minimumValue sets value to maximumValue. If NO, the stepper does not increment beyond maximumValue nor does it decrement below minimumValue but rather holds at those values.
The default value for this property is NO.
Availability
  • Available in iOS 5.0 and later.
Declared In
UIStepper.h

Instance Methods

backgroundImageForState:

Returns the background image associated with the specified control state.
- (UIImage *)backgroundImageForState:(UIControlState)state
Parameters
state
The control state in which the image is displayed.
Return Value
The background image used by the control when it is in the specified state.
Availability
  • Available in iOS 6.0 and later.
Declared In
UIStepper.h

decrementImageForState:

Returns the image used for the decrement glyph of the control.
- (UIImage *)decrementImageForState:(UIControlState)state
Parameters
state
The control state in which the image is displayed.
Return Value
The image used for the decrement glyph of the control.
Availability
  • Available in iOS 6.0 and later.
Declared In
UIStepper.h

dividerImageForLeftSegmentState:rightSegmentState:

Returns the divider image for the given combination of left and right states.
- (UIImage *)dividerImageForLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState
Parameters
leftState
The state of the left side of the control.
rightState
The state of the right side of the control.
Return Value
The image used for the specified combination of left and right states.
Availability
  • Available in iOS 6.0 and later.
Declared In
UIStepper.h

incrementImageForState:

Returns the image used for the increment glyph of the control.
- (UIImage *)incrementImageForState:(UIControlState)state
Parameters
state
The control state in which the image is displayed.
Return Value
The image used for the increment glyph of the control.
Availability
  • Available in iOS 6.0 and later.
Declared In
UIStepper.h

setBackgroundImage:forState:

Sets the background image for the control when it is in the specified state.
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
Parameters
image
The background image to use for the specified state.
state
The control state in which you want to display the image.
Discussion
For good results, image must be a stretchable image.
Availability
  • Available in iOS 6.0 and later.
Declared In
UIStepper.h

setDecrementImage:forState:

Sets the image to use for the decrement glyph of the control.
- (void)setDecrementImage:(UIImage *)image forState:(UIControlState)state
Parameters
image
The image to use for the decrement glyph.
state
The control state in which you want to display the image.
Discussion
The image you specify is composited on top of the control’s background to create the final control. If you do not specify a custom image, a minus (-) glyph is used.
Availability
  • Available in iOS 6.0 and later.
Declared In
UIStepper.h

setDividerImage:forLeftSegmentState:rightSegmentState:

Sets the image to use for the given combination of left and right states.
- (void)setDividerImage:(UIImage *)image forLeftSegmentState:(UIControlState)leftState rightSegmentState:(UIControlState)rightState
Parameters
image
The divider image to use.
leftState
The state of the left side of the control.
rightState
The state of the right side of the control.
Availability
  • Available in iOS 6.0 and later.
Declared In
UIStepper.h

setIncrementImage:forState:

Sets the image to use for the increment glyph of the control
- (void)setIncrementImage:(UIImage *)image forState:(UIControlState)state
Parameters
image
The image to use for the increment glyph.
state
The control state.
Discussion
The image you specify is composited on top of the control’s background to create the final control. If you do not specify a custom image, a plus (+) glyph is used.
Availability
  • Available in iOS 6.0 and later.
Declared In
UIStepper.h

No comments:

Post a Comment