Try out a tabbar with Swift UI

Tram Ho

First, start Xcode -> Create a new project -> Single View App -> Name the app and select the user interface SwiftUI Open the ContentView.swift file.

Delete all the old code, and add the following:

In the above code we are creating the tab bar page, currently just screens with color, this tab bar page will be decided according to the variable State index. The CirleTab code snippet is the part where we will render the tab bar.

Continue adding the following code:

In the code above we will see 4 tab bar button added. And there is a structure of code that is repeated, by checking the index variable. If the index is equal to the tab bar button index it will set the UI for the active button, and vice versa, it is inactive. You also need to add the corresponding image Asset to the tabbar buttons.

After completing the code, run it and you will get the following output

Share the news now

Source : Viblo