In this tutorial blog, we will see how to implement Slider control for iOS application using Objective-C Language.
Slider is a control used to select a single value from a continuous range of values. To do so, UISlider class is provided to implement slider control into your iOS project.
Example – In real scenario, it can be seen to increase/decrease brightness of your iPhone/iPad.
Following are the steps to implement Slider control:
Step 1: Open Xcode -> click on Create new Xcode project then choose Single View Application template under iOS tab as shown in below image and click Next button.
Step 2: Enter the product name as SliderDemo, select the Language as Objective-C and again click Next button as shown in below image. Later click Create button to create project appear on the next window.
Step 3: Adding UISlider & UILabel into the View Controller.
On your project, click on main.storyboard file available in the project navigator, and then select the UISlider from object library, drag into the superview of View Controller, it will look like below.
Slider control is having following properties:
It is the value which is getting printed as its initial value. Its default value of 0.5.
It is the value from where it gets started. Its default min. value is 0.
It is the value where it gets end. Its default max. value is 1.
Step 4: Declaring property for Slider & Label.
Select the Assistant Editor and create IBOutlet & IBAction property for UIStepper control by holding Ctrl button. It will open up a popup view like below then enter the Name as ‘stepper’ and ‘stepperClicked’ respectively and click Connect.
Both property (IBOutlet & IBAction) is defined because number will be displayed on Label on action event of Stepper control by calling its outlet property to access it value (as seen in below screenshot).
In the same manner, set up the IBOutlet property for Label object & name it as ‘lblValue’ and then hit ‘Enter’ button.
The all property defined in ViewController.h file will be shown as below:
Step 5: Complete Code in ViewController.m file
In ViewController.m file, displaying value of stepper will be passed to Label in stepper action method as shown in below screenshot.
Step 6: Finally, Build and Run the application where you will get the output like below.
Have Fun !
You can also watch its video on below link: