Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change stepper icons foreground color in SwiftUI?

Tags:

ios

swiftui

I'd like to change my steppers foreground color, and I can't find the property that works on it. I'd prefer to keep the standard stepper with the colors changed, and not have to create a custom one.

accentColor and foregroundColor don't work.

Stepper(value: $timer, in: 1...30) {
    Text("\(timer) " + "minutes")
        .foregroundColor(.red)
    }
    .accentColor(.red)
    .foregroundColor(.red)
}

This:

before

to this:

enter image description here

Is this even possible atm?

like image 302
956MB Avatar asked Nov 05 '25 16:11

956MB


1 Answers

Set setDecrementImage, setIncrementImage images in view init..

struct ContentView: View {
    init() {
        UIStepper.appearance().setDecrementImage(UIImage(systemName: "minus"), for: .normal)
        UIStepper.appearance().setIncrementImage(UIImage(systemName: "plus"), for: .normal)
    }
    var body: some View {
        Stepper(value: $timer, in: 1...30) {
            Text("\(timer) " + "minutes")
                .foregroundColor(.red)
            }
            .accentColor(.red)
            .foregroundColor(.red)
        }
    }
}
like image 162
Raja Kishan Avatar answered Nov 07 '25 10:11

Raja Kishan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!