Post

Replies

Boosts

Views

Activity

Reply to How to reverse the bounds parameter of a slider
Thanks to Javier from swiftui-lab. Here is what he posted: As far as I know, the Slider requires a range where the lower bound of the range is "lower" than the higher bound. You can work around that problem, if you use an intermediary binding, that converts the value. In the example below, I called it bridge: struct ExampleView: View {    @State private var value: Double = 0.5    let range = 0.3...1.3        var body: some View {      let bridge = BindingDouble(get: {        return range.upperBound - value + range.lowerBound      }, set: {        value = range.upperBound - $0 + range.lowerBound      })            Form {        Text("Value = \(value)")                Slider(value: bridge, in: range, onEditingChanged: {          print("\($0)")        })      }    } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21