One of the things that i like with the SwiftUI released with XCode 16 is the new way to write a TabView.
Now we can write:
struct ContentView: View { var body: some View { TabView { Tab("Contacts", systemImage: "rectangle.stack.person.crop.fill") { // Your View 1 } } Tab("Chat", systemImage: "message.fill") { // Your View 2 } Tab("Settings", systemImage: "gear") { // Your View 3 } } } }
In the Tab properties we define the title and the image, in the body the view that we want display when that tab is selected. It’s very clear way.
Instead before of that we have to do:
struct ContentView: View { var body: some View { TabView { // Your View1 .tabItem(Label("Contacts", systemImage: "rectangle.stack.person.crop.fill")) // Your View2 .tabItem(Label("Chats", systemImage: "message.fill")) // Your View3 .tabItem(Label("Settings", systemImage: "gear")) } } }
Less clear, we have to attach the .tabItem to every View, before declare the view and then the tabbar element.
In the next post i’ll disaplay a chat app example.
1 comment