<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UISearchBar",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UISearchBar"
  },
  "title" : "UISearchBar"
}
-->

# UISearchBar

A specialized view for receiving search-related information from the user.

```
@MainActor class UISearchBar
```

## Overview

[`UISearchBar`](/documentation/UIKit/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`](/documentation/UIKit/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`](/documentation/UIKit/UISearchTextField) and [`UISearchToken`](/documentation/UIKit/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

[`init()`](/documentation/UIKit/UISearchBar/init())

Initializes the search bar to its default state.

[`init(coder:)`](/documentation/UIKit/UISearchBar/init(coder:))

Creates a search bar from data in a given unarchiver.

[`init(frame:)`](/documentation/UIKit/UISearchBar/init(frame:))

Creates a search bar with a specified frame.

### Handling search bar interactions

[`delegate`](/documentation/UIKit/UISearchBar/delegate)

The search bar’s delegate object.

[`UISearchBarDelegate`](/documentation/UIKit/UISearchBarDelegate)

A collection of optional methods that you implement to make a search bar control functional.

### Getting the search text

[`placeholder`](/documentation/UIKit/UISearchBar/placeholder)

The string to display when there’s no other text in the text field.

[`prompt`](/documentation/UIKit/UISearchBar/prompt)

A single line of text displayed at the top of the search bar.

[`text`](/documentation/UIKit/UISearchBar/text)

The current or starting search text.

[`searchTextField`](/documentation/UIKit/UISearchBar/searchTextField)

The text field that the user enters a search query into.

### Configuring the search bar

[`isEnabled`](/documentation/UIKit/UISearchBar/isEnabled)

A Boolean value indicating whether the search bar is in the enabled state.

[`barTintColor`](/documentation/UIKit/UISearchBar/barTintColor)

The tint color to apply to the search bar background.

[`searchBarStyle`](/documentation/UIKit/UISearchBar/searchBarStyle)

A search bar style that specifies the search bar’s appearance.

[`UISearchBar.Style`](/documentation/UIKit/UISearchBar/Style)

Specifies whether the search bar has a background.

[`tintColor`](/documentation/UIKit/UISearchBar/tintColor)

The tint color to apply to key elements in the search bar.

[`isTranslucent`](/documentation/UIKit/UISearchBar/isTranslucent)

A Boolean value that indicates whether the search bar is translucent (true) or not (false).

[`barStyle`](/documentation/UIKit/UISearchBar/barStyle)

A bar style that specifies the search bar’s appearance.

[`UIBarStyle`](/documentation/UIKit/UIBarStyle)

Defines the stylistic appearance of different types of views.

### Customizing the keyboard shortcut items

[`inputAssistantItem`](/documentation/UIKit/UISearchBar/inputAssistantItem)

The input assistant to use for configuring the keyboard’s shortcuts bar.

### Configuring the search interface

[`showsBookmarkButton`](/documentation/UIKit/UISearchBar/showsBookmarkButton)

A Boolean value indicating whether the bookmark button is displayed.

[`showsCancelButton`](/documentation/UIKit/UISearchBar/showsCancelButton)

A Boolean value indicating whether the cancel button is displayed.

[`setShowsCancelButton(_:animated:)`](/documentation/UIKit/UISearchBar/setShowsCancelButton(_:animated:))

Sets the display state of the cancel button optionally with animation.

[`showsSearchResultsButton`](/documentation/UIKit/UISearchBar/showsSearchResultsButton)

A Boolean value indicating whether the search results button is displayed.

[`isSearchResultsButtonSelected`](/documentation/UIKit/UISearchBar/isSearchResultsButtonSelected)

A Boolean value indicating whether the search results button is selected.

### Customizing the search bar appearance

[`backgroundImage`](/documentation/UIKit/UISearchBar/backgroundImage)

The background image for the search bar.

[`backgroundImage(for:barMetrics:)`](/documentation/UIKit/UISearchBar/backgroundImage(for:barMetrics:))

Returns the image used for the background in a given position and with given metrics.

[`setBackgroundImage(_:for:barMetrics:)`](/documentation/UIKit/UISearchBar/setBackgroundImage(_:for:barMetrics:))

Sets the image to use for the background in a given position and with given metrics.

[`image(for:state:)`](/documentation/UIKit/UISearchBar/image(for:state:))

Returns the image for a given search bar icon type and control state.

[`setImage(_:for:state:)`](/documentation/UIKit/UISearchBar/setImage(_:for:state:))

Sets the image for a given search bar icon type and control state.

[`positionAdjustment(for:)`](/documentation/UIKit/UISearchBar/positionAdjustment(for:))

Returns the position adjustment for a given icon.

[`setPositionAdjustment(_:for:)`](/documentation/UIKit/UISearchBar/setPositionAdjustment(_:for:))

Returns the position adjustment for a given icon.

[`inputAccessoryView`](/documentation/UIKit/UISearchBar/inputAccessoryView)

A custom input accessory view for the keyboard of the search bar.

[`searchFieldBackgroundImage(for:)`](/documentation/UIKit/UISearchBar/searchFieldBackgroundImage(for:))

Returns the search text field image for a given state.

[`setSearchFieldBackgroundImage(_:for:)`](/documentation/UIKit/UISearchBar/setSearchFieldBackgroundImage(_:for:))

Sets the search text field image for a given state.

[`searchFieldBackgroundPositionAdjustment`](/documentation/UIKit/UISearchBar/searchFieldBackgroundPositionAdjustment)

The offset of the search text field background in the search bar.

[`searchTextPositionAdjustment`](/documentation/UIKit/UISearchBar/searchTextPositionAdjustment)

The offset of the text within the search text field background.

### Configuring scope bar buttons

[`scopeButtonTitles`](/documentation/UIKit/UISearchBar/scopeButtonTitles)

An array of strings indicating the titles of the scope buttons.

[`selectedScopeButtonIndex`](/documentation/UIKit/UISearchBar/selectedScopeButtonIndex)

The index of the selected scope button.

[`showsScopeBar`](/documentation/UIKit/UISearchBar/showsScopeBar)

Specifies whether the scope bar is displayed.

[`setShowsScope(_:animated:)`](/documentation/UIKit/UISearchBar/setShowsScope(_:animated:))

Specifies whether the scope bar is displayed, optionally using an animation.

### Customizing the scope bar appearance

[`scopeBarBackgroundImage`](/documentation/UIKit/UISearchBar/scopeBarBackgroundImage)

The background image for the scope bar.

[`scopeBarButtonBackgroundImage(for:)`](/documentation/UIKit/UISearchBar/scopeBarButtonBackgroundImage(for:))

Returns the background image for the scope bar button in a given state.

[`setScopeBarButtonBackgroundImage(_:for:)`](/documentation/UIKit/UISearchBar/setScopeBarButtonBackgroundImage(_:for:))

Sets the background image for the scope bar button in a given state.

[`scopeBarButtonDividerImage(forLeftSegmentState:rightSegmentState:)`](/documentation/UIKit/UISearchBar/scopeBarButtonDividerImage(forLeftSegmentState:rightSegmentState:))

Returns the divider image to use for a given combination of left and right segment states.

[`setScopeBarButtonDividerImage(_:forLeftSegmentState:rightSegmentState:)`](/documentation/UIKit/UISearchBar/setScopeBarButtonDividerImage(_:forLeftSegmentState:rightSegmentState:))

Sets the divider image to use for a given combination of left and right segment states.

[`scopeBarButtonTitleTextAttributes(for:)`](/documentation/UIKit/UISearchBar/scopeBarButtonTitleTextAttributes(for:))

Returns the text attributes for the search bar’s button’s title string for a given state.

[`setScopeBarButtonTitleTextAttributes(_:for:)`](/documentation/UIKit/UISearchBar/setScopeBarButtonTitleTextAttributes(_:for:))

Sets the text attributes for the search bar’ button’s title string for a given state.

### Managing dictation

[`isLookToDictateEnabled`](/documentation/UIKit/UISearchBar/isLookToDictateEnabled)

[`UILookToDictateCapable`](/documentation/UIKit/UILookToDictateCapable)

### Constants

[`UISearchBar.Icon`](/documentation/UIKit/UISearchBar/Icon)

Constants to identify the icons used in the search bar.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)