TabView in SwiftUI

DevTechie
DevTechie
Published in
4 min readAug 11, 2022

--

Photo by That's Her Business on Unsplash

SwiftUI TabView is a view which let’s us create Tab based UI(similar to UITabBarController). Tabs are displayed at the bottom of the window and we can select/display different views. Each tab in TabView is associated with a View and when user selects a specific tab, corresponding view shows up replacing the previous view.

Let’s start with a simple example.

struct ContentView: View {
var body: some View {
TabView {

}

}
}

This creates the bottom tab bar view.

Next, we will add views to TabView. We will add three Color views.

struct ContentView: View {
var body: some View {
TabView {
Color.blue
.edgesIgnoringSafeArea(.top)

Color.orange
.edgesIgnoringSafeArea(.top)

Color.mint
.edgesIgnoringSafeArea(.top)…

--

--