|
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
|
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
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.