BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

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 RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

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

Reply to this topic…

You need to create an account or log in to reply.

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.