NEW: Learn SwiftData for free with my all-new book! >>

Modify ProgressView with drag gestures

Forums > SwiftUI

Hi everyone!

Any idea how to modify (if is possible) a ProgressView with drag gestures. To begin with, I think the code will be something like this:

ProgressView(value: progress)

              // code here


But I'm really lost. Any help?



Lucas asks for help with a ProgressView:

Any idea how to modify, if possible, a ProgressView with drag gestures?

This is an odd use case for a ProgressView. Here's something similar, but using a Slider. Can you describe what you're trying to accomplish with a ProgressView?

// This Slider provide similar function to dragging a progressView.
struct ProgressView_Text: View {
    @State private var sliderValue = 0.0
    var randomValue: Double { sliderValue > 50 ? Double.random(in: 10...35) : Double.random(in: 55...90) }
    let highValue = 100.0
    var body: some View {
        VStack {
            ProgressView(value: sliderValue, total: highValue)
                .progressViewStyle(.linear).frame(height: 50)
            Text("Slider Value: \(sliderValue)").font(.title).padding(.vertical)
            Slider(value: $sliderValue, in: 0.0...highValue, step: 0.5).padding(.vertical)
            Button { sliderValue = randomValue }
                label: { Text("Random Value") }

Maybe instead of dragging a ProgressView, you might consider customizing a Slider view.

See -> Customizing a Slider in Swift


Hacking with Swift is sponsored by Judo

SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!

Try now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.