[ad_1]
How you can implement alternate record background colours in my SwiftUI lists to show system colours or customized colours.
import SwiftUI
struct FriendshipListView: View {
@EnvironmentObject var listViewModel: MenuListFriendshipViewModel
var physique: some View {
NavigationView {
Checklist {
//Use the $ syntax to cross a binding on to the subviews
ForEach($listViewModel.objects) { $merchandise in
MenuListRowView(merchandise: $merchandise)
}
}
.navigationBarTitle(Textual content("Friendships / Relationships"))
.listStyle(PlainListStyle())
}
}
}
struct ListView_Previews: PreviewProvider {
static var previews: some View {
FriendshipListView()
.environmentObject(MenuListFriendshipViewModel())
}
}
I used to be attempting to implement this code snippet however simply do not perceive easy methods to apply [index] to my ForEach loop.
Checklist {
ForEach(objects.indices) { index in
Textual content(objects[index])
.listRowBackground((index % 2 == 0) ? Coloration(.systemBlue) : Coloration(.white))
}
}
[ad_2]
