|
Alright, the title makes it sound pretty simple, but the problem I'm facing is that I'm rendering a list of buttons from one view file in another. I'm trying to create some type of ternary or conditional modifier so when a user taps one of the rendered buttons, the background color of only that button will toggle green, when they tap it again it returns to its previous color. My HomeView is the main view where the loop runs and pulls the UI from ContactCardView. ContactCardView has the details on how the information should display, including the default background coloring. What I cannot make sense of is where the conditional logic to change the background color should live. I've tried a few things with no success (@State variables in different places, ternary on the background color modifier). HomeView - The issue is mainly in the ScrollView at the bottom. The ForEach renders the device contacts using the ContactCardView UI.
ContactCardView - This is the UI being rendered in HomeView.
|
|
No sure if this is what you were after. I used
|
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
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.