TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

SOLVED: Bookworm - trying to add colors

Forums > 100 Days of SwiftUI

I'm trying to add colors to this NavigationStack. I want a single color for the entire background. At firt I got nothing. then I added a ZStack, even a VStack, but I get a red block between the top nav bar and the list. I know I'm overlooking something simple, but I can't quite figure it out.

There was an earlier post on the subject, but I cannot seem to apply the concepts on my view.

I appreciate your help.

var body: some View {

    NavigationStack(path: $path){
        ZStack {
            VStack {
                Color.red
                List(restaurants) {restaurant in
                    NavigationLink(value: restaurant) {
                        HStack {
                            Text(restaurant.location)
                            Text(restaurant.mainGrade)
                        }
                        .font(.system(size:18))
                        .foregroundColor(.green)
                    }
                }
                .navigationTitle("Restaurants")
                .toolbar {
                    Button("Add", systemImage: "plus") {
                        let restaurant = Restaurant(location: "New", eGrade: "A", sGrade: "A", cGrade: "A", rGrade: "A", bGrade: "A", mainGrade: "A")
                        modelContext.insert(restaurant)
                        path = [restaurant]
                    }
                    .navigationDestination(for: Restaurant.self) { restaurant in
                        EditRestaurauntView(restaurant: restaurant)
                    }
                }
            }
        }
    }

} }

2      

The same approach applies to your case. List is a scrollable content so you have to disable its background color first, then you can apply your own. No need for ZStack etc...

https://www.hackingwithswift.com/forums/100-days-of-swiftui/how-can-i-change-backgroundcolor-while-using-navigationstack/25159/25176

2      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.