ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • SwiftUI Grid - Pinned view 설정하기
    SwiftUI 100 레시피/Grid & Stacks 2022. 5. 26. 19:53

     

     

    import SwiftUI

     

    struct ContentView: View {

        

        let columns = [

            GridItem(.flexible(minimum: 100)),

            GridItem(.flexible(minimum: 100)),

            GridItem(.flexible(minimum: 100))

        ]

        

        private func headerView(_ index: Int) -> some View {

            Text("Section \(index)")

                        .font(.title)

                        .frame(maxWidth: .infinity)

                        .padding()

                        .background(Color.blue)

                        .foregroundColor(.white)

        }

        

        

        var body: some View {

            

            NavigationView{

            

                ScrollView{

                

                    LazyVGrid(columns: columns,  pinnedViews: [.sectionHeaders], content: {

                        

                        

                        ForEach(1..<11){ section in

                            

                            Section(header: headerView(section)){

                                

                                ForEach(1..<Int.random(in: 5...20)){ index in

                                    Text("Item \(index)")

                                        .padding()

                                        .background(Color.green)

                                        .foregroundColor(.white)

                                }

                            }

                        }

                    })

                }

                .navigationTitle("Pinned Views")

            }

        }

    }

     

    struct ContentView_Previews: PreviewProvider {

        static var previews: some View {

            ContentView()

        }

    }

     

     

    댓글

Designed by Tistory.