How to Create Range Slider programmatically in iOS?
Asked Answered
I

2

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];
Intratelluric answered 2/6, 2015 at 6:22 Comment(7)
Why do you assign 2 sliders in the same position?Prophylactic
It means two sliders in one position,, 1 is for minimum value and 2nd is for max value.. do you understand?Intratelluric
@Bannings-Because I want to show Range of age. like 16 to 22Intratelluric
create Custom control using UIView! OR if yo found some External APIs than just use it! what's the problem with that?Rainstorm
UISlider doesn't support two thumbs or a range. It only supports a single value.Volga
@rmaddy-Thats what I am Asking, Is there any way?Intratelluric
Whenever you add subview inside view at the same position, it will add subviews as stack items. Just think logically...it seems like you are trying to touch object that is behind a transparent wall.Pigeonhole
G
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

Goalie answered 2/6, 2015 at 6:47 Comment(3)
MARKRangeSlider is really great and intuitive, I've wasted half a day wrestling with NMRangeSliderLillielilliputian
I have used TTRangeSlider, It has many customisable featuresExcess
Those are all Obj-C, here are some Swift pods: github.com/yonat/MultiSlider and github.com/yhkaplan/DoubleSlider and github.com/BrianCorbin/SwiftRangeSliderCerellia
K
0

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

Kimberelykimberlee answered 15/1, 2016 at 14:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.