ios – Swift UI: TabView Inside scroll view does not work


I want to put a tabView inside a scroll View but when I do so the content of the tabview does not show up even though it is there. How can I fix this bug?

import SwiftUI

struct SwiftUIView: View {
    @State var selectedFilter = 1
    var body: some View {
        VStack {
            Color.blue.frame(height: 85) //header
            ScrollView {
                LazyVStack(spacing: 0, pinnedViews: [.sectionHeaders]) {
                    
                    
                    Color.green.frame(height: 100) //view body
                    
                    
                    //red color is tabview header
                    Section(header: Color.red.frame(height: 30)) {
                        //view content (THIS DOESNT SHOW)
                        TabView(selection: $selectedFilter) {
                            Color.yellow.frame(height: 800).tag(1)
                            Color.black.frame(height: 800).tag(2)
                            Color.indigo.frame(height: 800).tag(3)
                        }
                    }
                }
            }
        }
    }
}

#Preview {
    SwiftUIView()
}

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img