|
Hi, I am trying to modify the Stepper view's buttons (increment and decrement) so that the - button is green and the + button is red. How would I go about doing this properly in SwiftUI so that I maintain all of the current behavior of Stepper? |
|
This was an interesting challenge. Below is an attempt I made at doing this. I haven't thoroughly tested it out and there's probably better ways to do it, but it seems to work. You'll need to add the image to your Assets.
|
|
@vtabmow that's an interesting approach to the problem. One thing I noticed is that this does not display properly in dark mode. Also, when holding down the stepper button of the custom stepper view, it does not perform the same as the regular stepper. One more inconsistency between the two is that the button doesn't disable at range min/max, though that one shouldn't be too challenging to overcome. |
|
I kind of figured there'd be issues with it. I didn't realize you could hold down on the stepper and get it to increment or decrement like that. That could probably be handled with using gestures. You could create another image for dark mode and use something like this: https://www.hackingwithswift.com/quick-start/swiftui/how-to-detect-dark-mode#:~:text=SwiftUI%20lets%20us%20detect%20whether%20dark%20mode%20or,automatically%20be%20reloaded%20when%20the%20color%20scheme%20changes. to switch between images. And like you said the last one should be the easiest to fix. |
|
Here is my attempt at this. It's not very reusable at the moment, and the minus button seems to be slightly off for some reason regardless of how I try to hardcode the values in. Does anyone have a better way of doing this or have any additional tips?
|
|
I spent some more time trying to tackle this problem and this is my current solution. It's the best that I can come up with for now... thoughts? Oh and if someone has a better way... or a way that will enable the custom funcionality just for that view as listed in my TODO in the code comments please let me know! As a side note, it feels so great accomplishing something like this. HWS has really empowered me here. Thank you!
|
SPONSORED Transform your career with the iOS Lead Essentials. This Black Friday, unlock over 40 hours of expert training, mentorship, and community support to secure your place among the best devs. Click for early access to this limited offer and a free crash course.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.