UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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      

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.

Get it on Hacking with Swift+

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.