4

I want to create a bottom bar which should be common for all my page. Here I am posting the image:

Here

I know how to do it using storyboard. But how can I do it in SwiftUI?

0

2 Answers 2

39

This kind of view is called tab bar in iOS and in SwiftUI it is called TabView. It is declared like this:

var body: some View {
    TabView {
        Text("Favourites Screen")
            .tabItem {
                Image(systemName: "heart.fill")
                Text("Favourites")
        }
        Text("Friends Screen")
            .tabItem {
                Image(systemName: "person.fill")
                Text("Friends")
        }
        Text("Nearby Screen")
            .tabItem {
                Image(systemName: "mappin.circle.fill")
                Text("Nearby")
        }
    }
}

Tab bar

0

Alternatively, you can use Label view for giving name & icon of the tab:

struct BottomTabBar: View {
    var body: some View {
        TabView{
            Text("Profile Contents")
                .tabItem{
                    Label("Profile",systemImage: "person.fill")
                }
            Text("Tv Contents")
                .tabItem{
                    Label("Tv",systemImage: "tv.fill")
                }
        }
    }

}
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.