Thursday, 18 August 2016

How to create a Stepper in iOS using Objective C

Today we will learn how to create a Stepper in iOS.

Steps:

1. Create a new Project Lets say (StepperDemo).
2. Now go to StoryBoard and take stepper and a label from Object Library.



3. Now create property and ValueChanged Action for Stepper.

@property (weak, nonatomic) IBOutlet UILabel *stepperValueLabel;
@property (weak, nonatomic) IBOutlet UIStepper *stepper;
- (IBAction)valueChanged:(UIStepper *)sender {

   }


4.  Now go to ViewDidLoad and set the maximum and minimum value of Stepper.

   - (void)viewDidLoad {
                [super viewDidLoad];
                _stepper.minimumValue = 1;
                _stepper.maximumValue = 10;
                // Do any additional setup after loading the view, typically from a nib.
        }


5. Now write Button Action .

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

Now run the code and see the desired output.


Please do share Your comment and reviews ..
You can download the whole source code from here.

Enjoy Coding :)

No comments:

Post a Comment

Ads Inside Post

Blogger Widget