
- iOS Tutorial
- iOS - Home
- iOS - Getting Started
- iOS - Environment Setup
- iOS - Objective-C Basics
- iOS - First iPhone Application
- iOS - Actions and Outlets
- iOS - Delegates
- iOS - UI Elements
- iOS - Accelerometer
- iOS - Universal Applications
- iOS - Camera Management
- iOS - Location Handling
- iOS - SQLite Database
- iOS - Sending Email
- iOS - Audio & Video
- iOS - File Handling
- iOS - Accessing Maps
- iOS - In-App Purchase
- iOS - iAd Integration
- iOS - GameKit
- iOS - Storyboards
- iOS - Auto Layouts
- iOS - Twitter & Facebook
- iOS - Memory Management
- iOS - Application Debugging
- iOS Useful Resources
- iOS - Quick Guide
- iOS - Useful Resources
- iOS - Discussion
iOS - Sliders
Use of Sliders
Sliders are used to choose a single value from a range of values.
Important Properties
- continuous
- maximumValue
- minimumValue
- value
Important Method
- (void)setValue:(float)value animated:(BOOL)animated
Add Custom Methods addSlider and sliderChanged
-(IBAction)sliderChanged:(id)sender { NSLog(@"SliderValue %f",mySlider.value); } -(void)addSlider { mySlider = [[UISlider alloc] initWithFrame:CGRectMake(50, 200, 200, 23)]; [self.view addSubview:mySlider]; mySlider.minimumValue = 10.0; mySlider.maximumValue = 99.0; mySlider.continuous = NO; [mySlider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged]; }
Update viewDidLoad in ViewController.m as follows −
(void)viewDidLoad { [super viewDidLoad]; [self addSlider]; }
Output
When we run the application, we'll get the following output −

On dragging the slider, the output will be as follows and will print the new value in the console −

It is used to allow users to make adjustments to a value or process throughout a range of allowed values.
ios_ui_elements.htm
Advertisements