0
votes

I am trying to set the two sliders so that the maximum value between the two of them is 30. Thus is one slider is moved to the value of 20 the others max value is 10. Is this interaction possible and if so how? Heres my code on how I have tried to do it but no success.

var slider1:Float = 0.0
var slider2:Float = 0.0

@IBOutlet var Slider1Slider: UISlider!

@IBOutlet var Slider2Slider: UISlider!

func configureDefaultSlider2() {
    Slider2Slider.minimumValue = 0
    Slider2Slider.maximumValue = (30 - slider1)
    Slider2Slider.value = 0
    Slider2Slider.continuous = true
}
func configureDefaultSlider() {
    Slider1Slider.minimumValue = 0
    Slider1Slider.maximumValue = (30 - slider2)
    Slider1Slider.value = 0
    Slider1Slider.continuous = true
}


@IBAction func Slider1(sender: UISlider) {
    slider1 = sender.value
}

@IBAction func Slider2(sender: UISlider) {
    slider2 = sender.value
}
1
Do you want it like, If one's max value is 20 then the other's maximum value automatically becomes 10?Dhruv Ramani

1 Answers

0
votes

Here's what you should do:

@IBAction func Slider1(sender: UISlider) {
        slider1 = sender.value
        configureDefaultSlider2()
    }

    @IBAction func Slider2(sender: UISlider) {
        slider2 = sender.value
        configureDefaultSlider()
    }

Just call your functions.