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 String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.