Changing the Range of a UISlider Programmatically

北城余情 提交于 2019-12-10 18:01:04

问题


How is it possible to set the min max ranges of the UISlider programmatically?

For example (dummy code)

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

EDIT:

So I have the following:

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

This doesn't work, I still get it logging the value 0. Is this because I have set values in interface builder?


回答1:


Here is it.

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



回答2:


In the case updating selected values of IBOutlet-ed RangeSeekSlider

rangeSeekSlider.selectedMinValue = 10.0
rangeSeekSlider.selectedMaxValue = 100.0
rangeSeekSlider.setNeedsLayout()



回答3:


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


来源:https://stackoverflow.com/questions/7029644/changing-the-range-of-a-uislider-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!