Search code examples
iosswiftuislider

UISlider iOS app custom values in Swift


  let step: Float = 10000.0
  let roundedValue = round(sender.value / step) * step
  sender.value = roundedValue
  ProgressLabel.text = "\(sender.value) sqft"   

I have a single slider that needs to give 2 values when moved once the values are to be given through hard code.
I am not able to produce the desired result.
it should be exactly like we have in our design. Single Slider. When I slide each step will show the values as mentioned in the list.


Solution

  • If I understand the question correctly, you want the label to show custom values, like $5,000 - $10,000 sq.ft. $10,000 - $25,000 sq.ft. $25,000 - $50,000 sq.ft. $50,000 - $100,000 sq.ft. $100,000+ sq.ft

    If this is the case, why son't you use a simple switch statement or an if -else if - else block and add the logic there ?

    Something like:

    if (sender.value) < 0.05 {
        progressLabel.text = "too low"
    } else if (sender.value) < 0.2 {
        progressLabel.text = "$5,000 - $10,000 sq.ft."
    } else if (sender.value) < 0.8 {
        progressLabel.text = " $10,000 - $25,000 sq.ft.."
    } else 
        progressLabel.text = "$100,000+ sq.ft"
    }