14

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];
Cœur
  • 37,241
  • 25
  • 195
  • 267
M Swapnil
  • 2,361
  • 3
  • 18
  • 33

2 Answers2

33

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

Rahul Patel
  • 5,858
  • 6
  • 46
  • 72
  • 2
    MARKRangeSlider is really great and intuitive, I've wasted half a day wrestling with NMRangeSlider – etayluz Jul 19 '15 at 05:31
  • I have used TTRangeSlider, It has many customisable features – Arpit B Parekh Nov 18 '20 at 10:22
  • Those are all `Obj-C`, here are some `Swift` pods: https://github.com/yonat/MultiSlider and https://github.com/yhkaplan/DoubleSlider and https://github.com/BrianCorbin/SwiftRangeSlider – Lance Samaria Mar 11 '22 at 15:54
0

VPRangeSlider : You can also use this, which provides both segmented as well as un-segmented slider for iOS.

Varun
  • 759
  • 6
  • 12