# SwiftUI: how to create a Tab View

> Learn how to create a tab bar in SwiftUI with TabView, adding each screen with the tabItem modifier and a Label so users can switch by tapping an icon.

Author: Flavio Copes | Published: 2021-10-04 | Canonical: https://flaviocopes.com/swiftui-tabview/

It's common in iOS apps to use a Tab View. The one with a few choices at the bottom, and you can completely switch what's in the screen by tapping the icon / label.

SwiftUI conveniently provides us a view called `TabView`, which makes it easy to implement such a UI pattern.

Here's the simplest possible example of a TabView:

```swift
import SwiftUI

struct ContentView: View {
    
    var body: some View {
        TabView {
            Text("First")
                .tabItem {
                    Label("First", systemImage: "tray")
                }

            Text("Second")
                .tabItem {
                    Label("Second", systemImage: "calendar")
                }
        }
    }
}
```

And here's the result:

![iOS simulator showing SwiftUI TabView with First tab selected and tab bar with two icons at bottom](https://flaviocopes.com/images/swiftui-tabview/Screen_Shot_2021-10-02_at_18.37.29.jpg)

See? We have a `TabView` view, and inside it, we have 2 views.

Both are `Text` views to make it simple.

Their `tabItem` modifier will add them to the `TabView` with a label provided as a `Label` view.

Of course you will want to use a custom view instead of `Text` in most cases.
