TechnologiesSwiftUI

TabBarOnlyTabViewStyle struct

iOSmacOStvOSwatchOSvisionOS✓ renders

A tab view style that displays a tab bar when possible.

How it works

TabBarOnlyTabViewStyle is a TabViewStyle that presents a TabView strictly as a tab bar, suppressing any adaptive presentation the platform might otherwise choose, such as a sidebar on wider layouts. Reach for it when you want a TabView to keep its familiar bottom-tab appearance everywhere, rather than letting SwiftUI promote it to a sidebar or split layout based on size class or platform. You apply it through the tabViewStyle(_:) modifier using the static accessor .tabBarOnly, which resolves to an instance of this style.

  1. Build the navigation with a TabView

    The style only takes effect on a TabView, so the symbol always plugs in at the root of a tabbed container. Here that container is the TabView whose Tab children define Home, Search, and Profile.

  2. Select the style with .tabViewStyle(.tabBarOnly)

    tabViewStyle(_:) is the modifier that swaps a TabView's presentation. Passing the static member .tabBarOnly hands it a TabBarOnlyTabViewStyle value, instructing SwiftUI to render the tabs as a bar regardless of the available space.

  3. Let the tabs stay as a bar instead of adapting

    Without this style, a TabView may switch to a sidebar or split presentation in expanded environments. TabBarOnlyTabViewStyle pins the presentation to the tab-bar form, so the three Tab entries always appear as bar items rather than a sidebar list.

  4. Reach the style through its static accessor

    You rarely name TabBarOnlyTabViewStyle directly; the convenience .tabBarOnly on TabViewStyle constructs it for you and reads cleanly inside the modifier chain after .tabViewStyle.

Try it — Change .tabViewStyle(.tabBarOnly) to .tabViewStyle(.sidebarAdaptable) and run it in a wide layout to see how the same Tab items shift from a fixed tab bar to an adaptive 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.

TabBarOnlyTabViewStyle.swift
struct TabBarOnlyTabViewStyleDemo: View {
    var body: some View {
        TabView {
            Tab("Home", systemImage: "house") {
                Text("Home").padding()
            }
            Tab("Search", systemImage: "magnifyingglass") {
                Text("Search").padding()
            }
            Tab("Profile", systemImage: "person") {
                Text("Profile").padding()
            }
        }
        .tabViewStyle(.tabBarOnly)
    }
}
Live preview
Home Home Home Search Profile
Home Home Home Search Profile
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →