Sliders are used to choose a single value from a range of values.
- (void)setValue:(float)value animated:(BOOL)animated
-(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]; }
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.