Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

iOS Sliders (Sliders)

Use of IOS Sliders

A slider is used to select a value from a range of values.

Important Properties

Important Methods



- (void)setValue:(float)value animated:(BOOL)animated 

Add the 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];

}

Modify viewDidLoad in ViewController.m as follows



(void)viewDidLoad

{

   [super viewDidLoad];

   [self addSlider];

}

Output

Now when we run the application we will see the following output

sliderOutput1

The effect when dragging the slider is as follows:

sliderOutput2