Create a Simple Stepper Element in SwiftUI

To create a stepper in SwiftUI, check out the following code. It will give you a basic element which you can build upon, or use as is.

struct StepperView: View {
    @State var currentValue: Int

    var body: some View {
        HStack {
            Button("-") {
                guard currentValue > 0 else { return }
                currentValue -= 1
            }
            .foregroundColor(.white)
            .buttonStyle(.plain)
            
            Text(String(currentValue))
                .foregroundColor(.white)
                .padding(EdgeInsets(top: 0,
                                    leading: 15,
                                    bottom: 0,
                                    trailing: 15))
            Button("+") {
                currentValue += 1
            }
            .foregroundColor(.white)
            .buttonStyle(.plain)
        }
        .padding(EdgeInsets(top: 10,
                            leading: 20,
                            bottom: 10,
                            trailing: 20))
        .background(.green)
        .clipShape(Capsule())
    }
}

The result will look like this:

SwiftUI stepper view