Sagar...
Sagar...

Reputation: 1062

How to set UISlider value so it will be always at the center

I am looking for UISlider value which will set the indicator at the center.

iContrastSlider.minimumValue = 85; iContrastSlider.maximumValue = 200;

So, which value I need to set,so that indicator will be always @ center. I tried with all values but it always start from 0 as shown in image.

alt text

Thanks,

Sagar

Upvotes: 0

Views: 2071

Answers (3)

Satya
Satya

Reputation: 3330

Use the following code

float centerValue = ((iContrastSlider.maximumValue - iContrastSlider.minimumValue) / 2)+iContrastSlider.minimumValue;
[iContrastSlider setValue:centerValue animated:YES];

Upvotes: 4

Augustin A
Augustin A

Reputation: 127

add this into your slider iContrastSlider.minimumValue = 85/200; iContrastSlider.maximumValue = 200/200;

iContrastSlider.value = 115/200;

This will shows your slider value to center

Upvotes: 0

Jacob Relkin
Jacob Relkin

Reputation: 163238

Use simple math to calculate the average:

float centerValue = ((iContrastSlider.minimumValue + iContrastSlider.maximumValue) / 2) + iContrastSlider.minimumValue;
[iContrastSlider setValue:centerValue animated:YES];

Upvotes: 2

Related Questions