Search code examples
swiftuislider

Creating a Slider that changes maximum value if released at maximum


Probably a fairly basic error as I am fairly new to swift. I have an app that creates a slider with min and max values. These minimum and maximum values will only be a start point, so if someone sets the maximum value I would like to reset the maximum value to something greater.

In xcode I have linked the action to touch up inside.

@IBAction func increaseslider(Sender: AnyObject){
if slider.value = slider.maximumvalue{

I get errors at this point? Is there a simpler way to do this? Or I barking up the wrong tree?


Solution

  • One problem with your code that may be giving you errors:

    @IBAction func increaseslider(Sender: AnyObject){
    if slider.value = slider.maximumvalue{
    

    You need to use a double equals sign in the if clause:

    if slider.value == slider.maximumValue