Class

UISearchTextField

A view for displaying and editing text and search tokens.

Declaration

class UISearchTextField : UITextField

Overview

Use a search text field to display search criteria represented as text and tokens, and allow the user to edit that criteria. Tokens are discrete representations of nontextual content that your app can create and use to represent filters that limit the search results. Tokens always occur contiguously before any text in the search field.

UISearchBar hosts a search text field, but you may also use a search text field in other roles, such as the title view of a UINavigationItem.

Tokens can be programatically selected by including their position in a range assigned to the selectedTextRange property.

Topics

Converting Text into Tokens

func replaceTextualPortion(of: UITextRange, with: UISearchToken, at: Int)

Converts text in a search field into a search token.

var textualRange: UITextRange

The range of the field's text content.

Supporting Token Interactions

var allowsDeletingTokens: Bool

A Boolean that indicates whether the user can remove tokens from the search field.

var allowsCopyingTokens: Bool

A Boolean that indicates whether the user can copy or drag tokens from the search field.

var delegate: UITextFieldDelegate?

The receiver’s delegate.

protocol UISearchTextFieldDelegate

A method that supports cutting, copying, and dragging tokens from a search field.

protocol UISearchTextFieldPasteItem

A protocol that supports pasting tokens.

Adding and Removing Tokens

var tokens: [UISearchToken]

The collection of tokens in the search text field.

func insertToken(UISearchToken, at: Int)

Adds a search token at a specific index.

func removeToken(at: Int)

Removes a particular search token from the search text field.

Customizing Token Behavior

var tokenBackgroundColor: UIColor!

The background color for all tokens in the search text field.

func tokens(in: UITextRange) -> [UISearchToken]

Returns the search field's tokens that are within a given range.

func positionOfToken(at: Int) -> UITextPosition

Converts a token index into a text position.

See Also

Search Field

class UISearchToken

Search criteria in a search text field, represented by text and an optional icon.

protocol UISearchTextFieldDelegate

A method that supports cutting, copying, and dragging tokens from a search field.