UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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)
  .gesture(DragGesture()
        .onChanged({ 

              // code here

        })

But I'm really lost. Any help?

Thanks!

2      

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

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.