UISearchBar: searchTextField property
The searchTextField property is the text field inside the search bar, a UITextField.
Value
A UITextField.
- Read-only; assigning to it throws
TypeError. - Every read returns the same object.
- It shares the same text and the same keyboard settings with the search bar: its
textis the same value as the search bar'stext, and so isplaceholder; for the nine keyboard settings (keyboardType,returnKeyType, …), whichever side you write, the other side reads the new value. So writing these on the search bar alone is enough. - You need it for the text field members the search bar doesn't have, such as the font, the text color, and when the clear button is shown.
- Its
clearButtonModedefaults to'always'(the clear button is always at the right end when there is content); a newUITextFielddefaults to'never'. - When the search bar has focus, its
isFirstResponderis alsotrue.
Note: To observe text changes, use the search bar's
input.searchTextFieldis a control, and listening forinputon it also receives the user's typing, but whether it fires when the user taps the clear button is not verified in the simulator.
Examples
js
const search = new UISearchBar();
search.searchTextField.keyboardType = 'url';
console.log(search.keyboardType);
console.log(search.searchTextField.clearButtonMode);Result: Prints url and then always.
Corresponding iOS API
UISearchBar.searchTextField. The native type is UISearchTextField; here it is provided as a plain UITextField.