0PricingLogin
SwiftUI Academy · Lesson

Selected Tab Binding

Track and change the active tab in code.

Knowing the Active Tab

Sometimes your code needs to know or change which tab is showing. For that you bind the selection to your own state. 🎯

Give Each Tab a Tag

First mark each tab with a unique tag value so SwiftUI can identify which one is selected.

HomeScreen()
    .tabItem { Label("Home", systemImage: "house") }
    .tag(0)

All lessons in this course

  1. Building a Tab Bar
  2. Tab Items & Badges
  3. Selected Tab Binding
  4. Combining Tabs with Stacks
← Back to SwiftUI Academy