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];
4

2 回答 2

32

您在另一个滑块上方添加一个滑块。因此,根据 Cocoa-Touch 标准,只有顶部(新添加的)滑块将检测所有事件。当您在相同的帧值上添加两个滑块时,第一个滑块将无法触及。

有很多适用于 iOS 的 Range Slider 示例。以下是一些可能对您有所帮助的示例

于 2015-06-02T06:47:08.743 回答
1

VPRangeSlider:您也可以使用它,它为 iOS 提供分段和未分段的滑块。

于 2016-01-15T14:14:51.800 回答