O'Reilly logo

Programming iOS 4 by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

UISearchBar

A search bar (UISearchBar) is essentially a variety of text field, though it is not in fact a UITextField subclass. It is displayed as a rounded rectangle containing a magnifying glass icon, where the user can enter text (Figure 25-5). It does not, of itself, do any searching or display the results of a search; a common interface involves displaying the results of a search as a table, and a controller class, UISearchDisplayController, makes this easy to do (see Chapter 21).

A search bar with a search results button

Figure 25-5. A search bar with a search results button

A search bar’s current text is its text property. It can have a placeholder, which appears when there is no text. A prompt can be displayed above the search bar to explain its purpose. Delegate methods (UISearchBarDelegate) notify you of editing events:

  • searchBarShouldBeginEditing:
  • searchBarTextDidBeginEditing:
  • searchBar:textDidChange:
  • searchBar:shouldChangeTextInRange:replacementText:
  • searchBarShouldEndEditing:
  • searchBarTextDidEndEditing:

A search bar has a barStyle, for which your choices are the same as for a toolbar or navigation bar: either UIBarStyleDefault or UIBarStyleBlack, and if the latter, either translucent or not. Alternatively, the search bar may have a tintColor; as with a toolbar, if this is set, the barStyle is ignored. (See Chapter 19 and later in this chapter.) Because of this, a search bar looks good at the top of the screen, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required