Kyungyun Lee
Kyungyun Lee

Reputation: 135

swiftUI : How I can use H or VStack container with List in NavigationView

    import SwiftUI

struct FolderView: View {
    var body: some View {
        NavigationView{
            VStack{
                HStack{
                    Text("hi")
                }
                .frame(height : 50)
                .frame(maxWidth : .infinity)
                .background(.blue)
            
                
                List {
                    Text("hi")
                }
            }
            
            .navigationTitle("Task Folders 📁")
        }
    }
}

struct FolderView_Previews: PreviewProvider {
    static var previews: some View {
        FolderView()
    }
}

enter image description here

Hi! I tried to use Hstack container in NavigationView with List, But as you can see in my attached screenshot, it is working like that, I mean the container is mixed with navigationView Area.

Is there a some way that I can solve? How I can use that with List? Thank you!

Upvotes: 1

Views: 1616

Answers (1)

Asperi
Asperi

Reputation: 257711

Here is fixed variant - use as a background not a color but filled rectangle. Tested with Xcode 13.2 / iOS 15.2

demo

    HStack{
        Text("hi")
    }
    .frame(height : 50)
    .frame(maxWidth : .infinity)
    .background(Rectangle().fill(Color.blue))    // << here !!

Note: it is not clear for now whether that is a bug or a new NavigationView+background(color) feature.

Upvotes: 1

Related Questions