Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Create Range Slider programmatically in iOS?

I want to create a range slider. but wahen I assign 2 sliders in same position then only 1 is working. I found some External APIs to create Slider. Is there any way to create Range slider in iOS programmatically.

Here is my code..

  CGRect frame = CGRectMake(20, 330, 300, 60);

slider1 = [[UISlider alloc] initWithFrame:frame];
[slider1 addTarget:self action:@selector(sliderActionMin:) forControlEvents:UIControlEventValueChanged];
[slider1 setBackgroundColor:[UIColor clearColor]];
slider1.minimumValue = 0.0;
slider1.maximumValue = 55.0;
slider1.continuous = YES;
slider1.value= 16
slider1.contentMode=UIViewContentModeScaleToFill;
[self.view addSubview:slider1];


slider2 = [[UISlider alloc] initWithFrame:frame];
[slider2 addTarget:self action:@selector(sliderActionMin:) forControlEvents:UIControlEventValueChanged];
[slider2 setBackgroundColor:[UIColor clearColor]];
slider2.minimumValue = 0.0;
slider2.maximumValue = 55.0;
slider2.continuous = YES;
slider2.contentMode=UIViewContentModeScaleToFill;
slider2.value=[SingletonClass sharedSingleton].minAge;
[self.view addSubview:slider2];
like image 987
M Swapnil Avatar asked Jun 02 '15 06:06

M Swapnil


People also ask

What is UISlider?

A control for selecting a single value from a continuous range of values.

What is slider in Iphone?

watchOS. A slider is a horizontal track — appearing as a set of discrete steps or as a continuous bar — that represents a finite range of values. People can tap buttons on the sides of the slider to increase or decrease its value by a predefined amount.


1 Answers

You are adding one slider above another slider.So As per Cocoa-Touch standards, Only Top (newly added) slider will detect all events. First slider will be untouchable as you added both slider on same frame value.

There are so many Range Slider examples available for iOS. Below are few examples which may help you

  • MARKRangeSlider
  • NMRangeSlider
  • ACVRangeSelector
  • BJRangeSliderWithProgress
  • iosrangeslider
  • ASRangeSlider
  • TTRangeSlider
like image 80
Rahul Patel Avatar answered Oct 08 '22 16:10

Rahul Patel