以编程方式更改UISlider的范围

时间:2011-08-11 16:38:43

标签: iphone objective-c ios uislider

如何以编程方式设置UISlider的最小最大范围?

例如(虚拟代码)

UISlider* slider = [[UISlider alloc] init];
slider.min = -3;
slider.max = 3;

编辑:

所以我有以下内容:

sl.minimumValue = 5;
NSLog(@"MIN VAL: %d", sl.minimumValue);

这不起作用,我仍然记录值0.这是因为我在界面构建器中设置了值吗?

4 个答案:

答案 0 :(得分:10)

就是这样。

UISlider* slider = [[UISlider alloc] init];
slider.minimumValue = -3.0f;
slider.maximumValue = 3.0f;

答案 1 :(得分:0)

// Add a frame where you want to place the slider. This will place it at (x,y) = 0,0     
with a height of 10 and width of 200

CGRect frame = CGRectMake(0.0, 0.0, 200.0, 10.0);

// sliderAction will respond to the updated slider value
UISlider *slider = [[UISlider alloc] initWithFrame:frame];
[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];

// Set minimum and maximum value
slider.minimumValue = 0.0;
slider.maximumValue = 50.0;
slider.continuous = YES;

// Initial value
slider.value = 25.0;

// Add slider to view
[self.view addSubview:slider];

答案 2 :(得分:0)

如果更新 IBOutlet 版RangeSeekSlider

的选定值
rangeSeekSlider.selectedMinValue = 10.0
rangeSeekSlider.selectedMaxValue = 100.0
rangeSeekSlider.setNeedsLayout()

答案 3 :(得分:0)

迅速5:

self.yourSlider.minimumValue = 0.0
self.yourSlider.maximumValue = 4
self.yourSlider.value = 0