0

When put Image to the bottom of ZStack , image just not showing

 
 struct ContentView: View {
     var body: some View {
        VStack{
            ZStack{
                Image(systemName:"folder") // not showing
                    .resizable()
                    .scaledToFit()
                    .frame(width: 70, height: 70, alignment: .center)
                List {
                    ForEach(1...8, id: \.self){ i in
                        Text("ROW \(i)")
                    }
                }
            }
        }
    }
}

and image will show if it's on top.

 
 struct ContentView: View {
     var body: some View {
        VStack{
            ZStack{
                List {
                    ForEach(1...8, id: \.self){ i in
                        Text("ROW \(i)")
                    }
                }
                Image(systemName:"folder") // This will show
                    .resizable()
                    .scaledToFit()
                    .frame(width: 70, height: 70, alignment: .center)
            }
        }
    }
}

enter image description here

How can I show the image at bottom, and hide it when List scroll to the top of image?

1 Answer 1

2

You can achieve the result you are looking for by changing the background of the list like this:

struct ContentView: View {
    var body: some View {
        List {
            ForEach(1...8, id: \.self){ i in
                Text("ROW \(i)")
            }
        }
        .background(
            ZStack {
                // Apply the default list background color in case you want it
                Color(UIColor.systemGroupedBackground)
                    .edgesIgnoringSafeArea(.all)
                
                Image(systemName: "folder")
                    .resizable()
                    .scaledToFit()
                    .frame(width: 70, height: 70, alignment: .center)
            }
        )
        .scrollContentBackground(.hidden)
    }
}

Screenshot of the result

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.