how to fix interval on UISlider,iphone - iphone

I have Slider,which works perfect.
But what i am trying to do is,
for ex, min =0 and max=50 and x=0
every time i slide or use buttons to change the value of slider, the interval should be of 5 only.
i.e x should be equal to only 0,5,10,15.....50
Suggestions.
Thanks

In the callback (value changed) - read the value, round it up or down to the nearest increment of 5, then set the slider to your preferred value. That way, it will 'jump' between your preferred values.

Related

How to change "SelectOut "probability using the slider?

How to change SelectOut probability using the slider in Anylogic?
to get the value of the slider you do
slider.getValue()
You need to be sure that the minimum and maximum of the slider is set from 0 to 1 as minimum and maximum values.
You write slider.getValue() on the probability field of your select output block

How to make the set of possible values for UISlider an open interval?

I am using a UISlider to allow a user to choose among four options. I ask the user a question of the form "how much do you like this thing?", they respond by moving the slider, and then behind the scenes I map the value of the slider to one of four elements of an array. I want the first quarter of the slider to correspond to the first element of the array, the second quarter of the slider to correspond to the second element of the array, and so on.
By default, the range of a slider is [0,1], so one natural way to do what I want is:
let index = Int(rangedSlider.value * Float(currentAnswers.count) )
assuming that rangedSlider is the name of the outlet connected to the UISlider in question, and currentAnswers is the array of answers I'm mapping to. The issue with this is that if the user moves the slider all the way to the right, that sets the value of the slider to 1, which maps to index 4 by the formula above (assuming there are four answers). I can always add an additional line of code that takes care of that case separately,
if rangedSlider.value == 1 { index = currentAnswers.count - 1 }
but I prefer a one line solution.
I can also set the max value of the slider to 0.99 in the Storyboard and stick with the first line of code I wrote, but I want to know: is there a built-in way to make the range of UISlider values an open interval? Is there a better way to get the behavior I want?
Is this any more complicated than:
let index = Int(rangedSlider.value * Float(currentAnswers.count - 1))
Or have I misunderstood the problem you're having?
That way your index will be returned as a number between 0 and 3 with 0 corresponding to the first answer and 3 corresponding to the fourth answer.

Is there a way to set the amount a sliders value changes when you use it?

I'm am trying to make it so that when you interact with a slider, it goes up or down by 5. I know you can make it go up in whole numbers but can you change the base value that it increases/decreases by?
Not a built-in feature unfortunately. The workaround is to enable Whole Numbers, and set:
Slider min = Actual min / Step
Slider max = Actual max / Step
Then in your code you can do Actual value = Slider value * Step
Or you can write your own slider component with stepping support.
PS: I know, it sucks.

Interface variables - sliders affecting sliders

Let's say I have two sliders on my interface. Slider one goes from 0-500 and slider two goes from 0-100.
Is there anyway of setting it so that the value of slider one influences the possible values for slider two. So if I set slider one to 500, slider two can only be values from 0-30, for example.
Alternatively it would not necessarily have to be a slider affecting another slier, it could be a button. So if I have buttons A and B, if I select A the slider can be 0-10 but if I select B only 20-50.
Bit of a strange query I admit, I've just been tasked with making an interactive "model" for kids to try out different systems.
Thanks for taking the time to read this.
Yes, you can do this. Example: make 3 sliders: test0, test1, test2. Let the min and max values of test0 be test1 and test2. Let the min and max values of test1 be 0 and 5, and set a value of 1. Let the min and max values of test2 be 95 and 100, and set a value of 99. Your test0 slider will now work as hoped.
BUT what happens if you make the min and max values of test0 to test2 and test1? OK, you get odd behavior, which is likely to look broken to your "kids". So ... this arrangement is not a good one. If you describe your goals in more details, maybe we can find a better solution.

How to set the interval of my UISlider such that it shows the value only in some whole numbers

In my app I want to set the interval of slider. I have a slider which shows the value in the bubble and I want to display the value only in some whole numbers. Let's say if I have min and max value of 0-1000 and I want to increase the value by 25 and not like 1-2-3-4.
Any suggestions??
Thanks,
Let the slider use its natural range internally, and simply convert the value for output by multiplying it by the increment. For a 0-1000 slider, you'd set the maximumValue property to 40 (that's 1000 / 25) and then multiply that value by 25 to get the output value.
try.
//fix slider value =0;
//some method to run slider value 0-1000
{
slider.value=slider.value+25;
}
You can create a subclass of UISlider, probably called StepSlider which has a single property stepSize. Relevant UISlider properties would be overriden to bridge the values between the consumer of the class and the superclass. Example source,