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.
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 theTabViewwhoseTabchildren defineHome,Search, andProfile.Select the style with .tabViewStyle(.tabBarOnly)
tabViewStyle(_:)is the modifier that swaps aTabView's presentation. Passing the static member.tabBarOnlyhands it aTabBarOnlyTabViewStylevalue, instructing SwiftUI to render the tabs as a bar regardless of the available space.Let the tabs stay as a bar instead of adapting
Without this style, a
TabViewmay switch to a sidebar or split presentation in expanded environments.TabBarOnlyTabViewStylepins the presentation to the tab-bar form, so the threeTabentries always appear as bar items rather than a sidebar list.Reach the style through its static accessor
You rarely name
TabBarOnlyTabViewStyledirectly; the convenience.tabBarOnlyonTabViewStyleconstructs it for you and reads cleanly inside the modifier chain after.tabViewStyle.
.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.
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)
}
}