UISearchBar
A specialized view for receiving search-related information from the user.
Declaration
@MainActor class UISearchBarOverview
UISearchBar provides a text field for entering text, a search button, a bookmark button, and a cancel button. A search bar doesn’t actually perform any searches. You use a delegate, an object conforming to the UISearchBarDelegate protocol, to implement the actions when the user enters text or clicks buttons. For details about interacting with the text field, accessing its content, and using tokens, see UISearchTextField and UISearchToken.
Customize appearance
You can customize the appearance of search bars one at a time, or you can use the appearance proxy ([UISearchBar appearance]) to customize the appearance of all search bars in an app.
In general, you should specify a value for the normal state to be used by other states which don’t have a custom value set. Similarly, when a property is dependent on the bar metrics (on iPhone, in landscape orientation bars have a different height from standard), you should specify a value for UIBarMetricsDefault.
Topics
Creating a search bar
Handling search bar interactions
Getting the search text
Configuring the search bar
Customizing the keyboard shortcut items
Configuring the search interface
showsBookmarkButtonshowsCancelButtonsetShowsCancelButton(_:animated:)showsSearchResultsButtonisSearchResultsButtonSelected
Customizing the search bar appearance
backgroundImagebackgroundImage(for:barMetrics:)setBackgroundImage(_:for:barMetrics:)image(for:state:)setImage(_:for:state:)positionAdjustment(for:)setPositionAdjustment(_:for:)inputAccessoryViewsearchFieldBackgroundImage(for:)setSearchFieldBackgroundImage(_:for:)searchFieldBackgroundPositionAdjustmentsearchTextPositionAdjustment
Configuring scope bar buttons
Customizing the scope bar appearance
scopeBarBackgroundImagescopeBarButtonBackgroundImage(for:)setScopeBarButtonBackgroundImage(_:for:)scopeBarButtonDividerImage(forLeftSegmentState:rightSegmentState:)setScopeBarButtonDividerImage(_:forLeftSegmentState:rightSegmentState:)scopeBarButtonTitleTextAttributes(for:)setScopeBarButtonTitleTextAttributes(_:for:)