ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • #10. 목록띄우기
    SwiftUI 앱만들기 2022. 7. 7. 13:18

    #1. ContentView

     

    import SwiftUI

     

    struct ContentView: View {

        

        @State var isNavigtionBarHidden : Bool = false

        

        var body: some View {

            

            NavigationView{

                ZStack(alignment: .bottomTrailing) {

                    

                    VStack(alignment:.leading, spacing: 0) {

                        

                        HStack{

                            NavigationLink(destination: MyList(isNavigationBarHidden: self.$isNavigtionBarHidden)){

                                Image(systemName: "line.horizontal.3").font(.largeTitle)

                                    .foregroundColor(.black)

                            }

                            

                            

                            Spacer()

                            Image(systemName: "person.crop.circle.fill").font(.largeTitle)

                        }

                        .padding(20)

                        

                        

                        

                        Text("정대리 할 일 목록")

                            .font(.system(size: 40))

                            .fontWeight(.black)

                            .padding(.top, 10)

                            .padding(.horizontal,10)

                        

                        

                        ScrollView{

                            VStack{

                                MyProjectCard()

                                MyBasicCard()

                                MyCard(icon: "tray.fill", title: "정리하기", start: "10AM", end: "11 AM", bgColor: Color.blue)

                                MyCard(icon: "gamecontroller.fill", title: "게임하기", start: "10PM", end: "11 PM", bgColor: Color.orange)

                                

                            }.padding()

                        }

                    }

                    .padding(.top, 10)

                    .padding(.horizontal,10)

                    

                    

                    

                    Circle().foregroundColor(Color.yellow)

                        .frame(width:60, height: 60)

                        .overlay{

                            Image(systemName: "plus")

                                .font(.system(size: 30))

                                .foregroundColor(.white)

                        }

                        .padding(10)

                        .shadow(radius: 20)

                

                } // ZStack

                

                //NavigationTitle 없애기

                .navigationTitle("뒤로가기")

                .navigationBarHidden(self.isNavigtionBarHidden)

                .onAppear{

                    self.isNavigtionBarHidden = true

                }

            }// NavigationView

            

            

            

        }

    }

     

    struct ContentView_Previews: PreviewProvider {

        static var previews: some View {

            ContentView()

        }

    }

     

    #2. MyList

     

    import SwiftUI

     

    struct MyList: View {

        

        @Binding var isNavigationBarHidden : Bool

        

        //리스트 중간 선 없애기

        init(isNavigationBarHidden : Binding<Bool> = .constant(false)) {

               

               if #available(iOS 14.0, *){

                   

               } else {

                   UITableView.appearance().tableFooterView = UIView()

               }

               

               UITableView.appearance().separatorStyle = .none

               

            _isNavigationBarHidden = isNavigationBarHidden

               

           }

        

        var body: some View {

            

    //        List{

    //            ForEach(1...20, id:\.self){

    //                Text("마이리스트 \($0)")

    //            }

    //        }

            List{

                

                Section(

                    header: Text("Header #1")

                        .font(.headline).foregroundColor(Color.black)

                    ,

                    footer: Text("Footer #1")

                

                ){

                    ForEach(1...3, id:\.self){ itemIndex in

                        //Text("마이리스트 \(itemIndex)")

                        MyCard(icon: "book.fill", title: "Reading \(itemIndex)", start: "1 PM", end: "3 PM", bgColor: Color.green)

                    }

                } //Section #1

                //리스트 간격조절

                .listRowInsets(EdgeInsets.init(top: 10, leading: 10, bottom: 10, trailing: 10))

                //리스트 백그라운드 칼러

                .listRowBackground(Color.orange)

                

                

                Section(

                    header: Text("Header #2")

                    .font(.headline).foregroundColor(Color.black)

                ,

                footer: Text("Footer #2")

                ){

                    ForEach(1...10, id:\.self){ itemIndex in

                        //Text("마이리스트 \(itemIndex)")

                        MyCard(icon: "book.fill", title: "Reading \(itemIndex)", start: "1 PM", end: "3 PM", bgColor: Color.blue)

                    }

                } //Section #2

                .listRowInsets(EdgeInsets.init(top: 10, leading: 10, bottom: 10, trailing: 10))

            }

            //.listStyle(PlainListStyle) //기본 스타일

            .listStyle(GroupedListStyle())

            .navigationBarTitle("내목록")

            .onAppear(){

                self.isNavigationBarHidden = false

            }

        }

    }

     

    struct MyList_Previews: PreviewProvider {

        static var previews: some View {

            MyList()

        }

    }

     

     

    'SwiftUI 앱만들기' 카테고리의 다른 글

    #12. 지오메트리리더(GeometryReader)  (0) 2022.07.07
    #11. 내비게이션(Navigation) 뷰  (0) 2022.07.07
    #9. 래이아웃(Layout2)  (0) 2022.07.07
    #8. 래이아웃(Layout1)  (0) 2022.07.05
    #7-스택(Stacks)  (0) 2022.07.05

    댓글

Designed by Tistory.