Sunday, June 20, 2021

Swift UI how to add Tab bar

this is pretty straight forward 

The below code includes a TabView and a Navigation View component 

var body: some View {

//        MainView()

//            .environmentObject(accountCreation)

        TabView (selection: $selection){

            NavigationView {

                List(1...10, id: \.self) { index in

                    NavigationLink(

                        destination: Text("Item #\(index) Details"),

                        label: {

                            Text("Item #\(index)")

                                .font(.system(size: 20, weight: .bold, design: .rounded))

                        })

             

                    }

             

                    .navigationTitle("TabView Demo")

                }

                .tabItem {

                    Image(systemName: "house.fill")

                    Text("Home")

                }

                .tag(0)

            .tag(0)

     

        Text("Bookmark Tab")

            .font(.system(size: 30, weight: .bold, design: .rounded))

            .tabItem {

                Image(systemName: "bookmark.circle.fill")

                Text("Bookmark")

            }

            .tag(1)

}

 references:

https://www.hackingwithswift.com/quick-start/swiftui/adding-tabview-and-tabitem

No comments:

Post a Comment