The placement of a search field in a view hierarchy.
You can give a preferred placement to any of the searchable modifiers, like
``View/searchable(text:placement:prompt:)``:
var body: some View {
NavigationView {
PrimaryView()
SecondaryView()
Text("Select a primary and secondary item")
}
.searchable(text: $text, placement: .sidebar)
}
Depending on the containing view hierachy, SwiftUI might not be able to
fulfill your request.
Members (6)
get · iOS 15.0+
toolbarPrincipal
TypeScript
static get toolbarPrincipal(): SearchFieldPlacement
Swift declaration
static var toolbarPrincipal: SearchFieldPlacement { get }
The search field appears in the principal section of the toolbar.
See `ToolbarItemPlacement.principal` for more information.
The search field appears in the navigation bar using the specified
display mode.
The field appears below any navigation bar title. The system can
hide the field in response to scrolling, depending on the `displayMode`
that you set.
- Parameter displayMode: A control that indicates whether to hide
the search field in response to scrolling.
get · iOS 15.0+
navigationBarDrawer
TypeScript
static get navigationBarDrawer(): SearchFieldPlacement
Swift declaration
static let navigationBarDrawer: SearchFieldPlacement
The search field appears in the navigation bar.
The field appears below any navigation bar title and uses the
``NavigationBarDrawerDisplayMode/automatic`` display mode to configure
when to hide the search field. To choose a different display mode,
use ``navigationBarDrawer(displayMode:)`` instead.
get · iOS 15.0+
sidebar
TypeScript
static get sidebar(): SearchFieldPlacement
Swift declaration
static var sidebar: SearchFieldPlacement { get }
The search field appears in the sidebar of a navigation view.
The precise placement depends on the platform:
* In iOS and iPadOS the search field appears in the section of
the navigation bar associated with the sidebar.
* In macOS the search field appears as a sticky header in the sidebar,
attached to the toolbar.
If a sidebar isn't available, like when you apply the searchable
modifier to a view other than a navigation split view, SwiftUI uses
automatic placement instead.
- Note: The search field appears inline with
the sidebar's content when building with the Xcode 16 SDKs or earlier.
get · iOS 15.0+
toolbar
TypeScript
static get toolbar(): SearchFieldPlacement
Swift declaration
static let toolbar: SearchFieldPlacement
The search field appears in the toolbar.
The precise placement depends on the platform:
* In iOS and watchOS, the search field appears below the
navigation bar and is revealed by scrolling.
* In iPadOS, the search field appears in the trailing
navigation bar.
* In macOS, the search field appears in the trailing toolbar.
get · iOS 15.0+
automatic
TypeScript
static get automatic(): SearchFieldPlacement
Swift declaration
static let automatic: SearchFieldPlacement
SwiftUI places the search field automatically.
Placement of the search field depends on the platform:
* In iOS, iPadOS, and macOS, the search field appears in the toolbar.
* In tvOS and watchOS, the search field appears inline with its
content.