Crossed Ads

Tuesday 27 June 2017

How to implement Slider in iOS using Objective-C with Xcode 8 ? (Blog)

Slider control in iOS (Objective-C)


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:

Value
It is the value which is getting printed as its initial value. Its default value of 0.5.

Minimum Value
It is the value from where it gets started. Its default min. value is 0.

Maximum Value
It is the value where it gets end. Its default max. value is 1.


In the same manner, Label object will also be placed using drag & drop method into View Controller to show the value of Stepper control.

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 ‘lblStatus’ 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:




3 comments:

  1. Definitely more interesting topics will be shared soon...

    ReplyDelete
  2. Thank you for your compliment!
    Always happy to help in simplest way.

    ReplyDelete
  3. Awesome Blog! it is very informative and you are obviously very knowledgeable in this area. You have opened my eyes to varying views on this topic with solid content.for information.

    Digital Marketing Training in Chennai

    Digital Marketing Course in Chennai

    ReplyDelete