TechnologiesSwiftUI

TabCustomizationBehavior struct

iOSmacOStvOSwatchOSvisionOSiOS 18.0+✓ renders

The customization behavior of customizable tab view content.

How it works

TabCustomizationBehavior describes how much control a person has over an individual tab when a TabView enters customization mode — whether they can move it, hide it, or neither. You attach a behavior to a tab to opt it into reordering, lock it in place, or remove it from the customization UI entirely, giving you per-tab authority over an experience that is otherwise driven by the user. Reach for it whenever a sidebar-adaptable TabView exposes customization and certain tabs must stay fixed or remain immutable while others are free to be rearranged.

  1. Choose a behavior with the type's static members

    TabCustomizationBehavior supplies the named cases that express intent: .reorderable lets a person move the tab among its peers, while .disabled excludes the tab from customization so it cannot be moved or hidden. You select one of these values and hand it to the tab; in the example .reorderable frees the Browse tab and .disabled pins the Settings tab.

  2. Apply it with customizationBehavior(_:for:)

    The customizationBehavior(_:for:) modifier binds a TabCustomizationBehavior to a tab for one or more placements. The first argument is the behavior; the variadic for: argument lists the surfaces it governs. In the example, .customizationBehavior(.reorderable, for: .sidebar, .tabBar) and .customizationBehavior(.disabled, for: .sidebar, .tabBar) apply each behavior to both the sidebar and the tab bar at once.

  3. Give each tab a stable customizationID

    A behavior only takes effect on a tab that SwiftUI can identify across launches, so each Tab is tagged with customizationID(_:)"tab.home", "tab.browse", and "tab.settings". This identity is what lets the framework remember and persist a tab's customized state alongside the behavior you declared for it.

  4. Persist state through tabViewCustomization(_:)

    The behaviors operate against a TabViewCustomization value that records what the person has changed. You hold it in @State private var customization = TabViewCustomization() and bind it with .tabViewCustomization($customization) so reordering and visibility edits are captured; tabs marked .disabled simply never contribute changes to it.

  5. Enable customization with a sidebar-adaptable style

    Customization, and therefore TabCustomizationBehavior, is meaningful only when the TabView presents an editable layout. The .tabViewStyle(.sidebarAdaptable) modifier provides the sidebar-and-tab-bar presentation whose .sidebar and .tabBar placements your behaviors target.

Try it — Change the Settings tab's .customizationBehavior(.disabled, for: .sidebar, .tabBar) to .reorderable and watch a previously locked tab become draggable in the sidebar.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

TabCustomizationBehavior.swift
struct TabCustomizationBehaviorDemo: View {
    @State private var customization = TabViewCustomization()

    var body: some View {
        TabView {
            Tab("Home", systemImage: "house") {
                Text("Home").padding()
            }
            .customizationID("tab.home")

            Tab("Browse", systemImage: "square.grid.2x2") {
                Text("Browse").padding()
            }
            .customizationID("tab.browse")
            .customizationBehavior(.reorderable, for: .sidebar, .tabBar)

            Tab("Settings", systemImage: "gearshape") {
                Text("Settings").padding()
            }
            .customizationID("tab.settings")
            .customizationBehavior(.disabled, for: .sidebar, .tabBar)
        }
        .tabViewStyle(.sidebarAdaptable)
        .tabViewCustomization($customization)
        .padding()
    }
}
Live preview
Home Home Browse Settings
Home Home Browse Settings
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →