How to change min-max values ​​of UISlider?

Is there a good way to change the values ​​of a UISlider? The default value is min on the left and maximum on the right. I would like it to work the other way around.

Rotating 180 degrees seems a little silly. Any ideas?

Thanks!

+6
source share
8 answers

Just subtract the value you get from the slider from the maximum value that will change the values.

+8
source

Then I needed the same thing as you ... so I turned it 90 degrees, putting it in an inverted position. The slider is symmetrical, so it looks the same in both positions. But the min and max values ​​are now the opposite.

Command...

mySlider.transform = CGAffineTransformRotate(mySlider.transform, 180.0/180*M_PI); 
+4
source

Subclass of NSSlider / UISlider. So, override these two methods -

 //Assumes minValue not necessarily 0.0 -(double)doubleValue { double minVal = [self minValue]; double maxVal = [self maxValue]; double curValue = [super doubleValue]; double reverseVal = maxVal - curValue + minVal; return reverseVal; } -(void)setDoubleValue:(double)aDouble { double minVal = [self minValue]; double maxVal = [self maxValue]; double reverseVal = maxVal - aDouble + minVal; [super setDoubleValue:reverseVal]; } 

This will lead to an inversion of the values, allowing to show at least on the right / up, and at the maximum on the left / bottom

+2
source

Just subtract the slider current value from the maximum value.

 label.text = [NSString stringWithFormat:@" %.f%% ", 100 - self.slider.value]; 
0
source

You can simply flip the slider horizontally using a transformation (Swift 5.0):

 slider.transform = CGAffineTransform(scaleX: -1, y: 1); 
0
source

How about this:

 slider.maximumValue = -minimumValue; slider.minimumValue = -maximumValue; -(void) sliderChanged:(UISlider *) slider { float value = -slider.value; // do something with value } 

Then just use -slider.value.

0
source

The accepted answer is incorrect, as it assumes that the value of the Min slider is 0.

In my case, my Min 1.1 and Max 8.0

You need to subtract the value of the slider from the value of Min + Max in order to invert the value.

0
source

Try this beautiful line -

 yourSlider.semanticContentAttribute = .forceRightToLeft 

This changes the colors of the min-max track + inverts the values ​​+ you don’t lose your frame, as in the answers to the conversion.

0
source

All Articles