Twitter LogoFacebook Logo
Tab
Hello, in this tutorial, I will show you how to add the Tab View from Swift UI.
By: King
Image from Codeible.com

The TabView is a view that allows you to switch between views by interacting with its UI

Adding the Tab View

To add it to your layout, open the XCode library, search for Tab View, and drag it inside the layout.

Image from Codeible.com

Adding Tabs

To create the tabs, place a View in between the curly brackets of the Tab View.  Then apply the tabItem() modifier to create the tab button. 


For the button content, add a Label.

Image from Codeible.com

The Tab View only support buttons with a Text and Image. Any other views will not be displayed.

Using Custom Views

The TabView is also not limited to Text views. We can use anything as long as it is a View. 

In my project, there are a couple of views that were defined. You can get the code using this link

Instead of using Text views, I can replace them with the custom views they’ll be displayed.


Sign In