Satisfaction Slider SwiftUI

Hi All,

I have a slider,

Code Block  
@State private var appearance: Double = 4
Slider(value: $appearance, in: 1...7, step: 1)


I would like to use this slider for the scale:

Terrible,
Very poor,
Poor,
Average ......etc

The slider gives me the values 1-7 how can I turn these into a string to show on the screen?

Thanks all
Answered by OOPer in 616936022
Something like this?
Code Block
struct ContentView: View {
    @State private var appearance: Float = 4
    let appearanceText = [
        "Terrible",
        "Very poor",
        "Poor",
        "Average",
        "...", "...", "..."
    ]
    var body: some View {
        VStack {
            Text("appearance: \(appearanceText[Int(appearance)-1])")
            Slider(value: $appearance, in: 1...7, step: 1)
        }
    }
}

You may want to consider internationalization, but that is another issue...
Accepted Answer
Something like this?
Code Block
struct ContentView: View {
    @State private var appearance: Float = 4
    let appearanceText = [
        "Terrible",
        "Very poor",
        "Poor",
        "Average",
        "...", "...", "..."
    ]
    var body: some View {
        VStack {
            Text("appearance: \(appearanceText[Int(appearance)-1])")
            Slider(value: $appearance, in: 1...7, step: 1)
        }
    }
}

You may want to consider internationalization, but that is another issue...
So that's perfect for the questions that I asked....

I have 10 of these sliders on this page.....

Will I need to declare the options array for each?

Will I need to declare the options array for each?

Yes, if you want to show different text set for each slider.
If some of the sliders show exactly the same set, the array can be shared.


Apologies, that's pretty obvious when you look at it.

100% Solved with the info provided
Satisfaction Slider SwiftUI
 
 
Q