Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
UISearchBar - iPhone Development Wiki


From iPhone Development Wiki
Revision as of 20:33, 4 December 2009 by KennyTM~ (talk | contribs) (Created page with 'UISearchBar is a rounded text field which a search icon. [[Image:UISearchBarSamples.png|right|frame|Examples of some UISearchBars. '''Top:''' having custom backgroundImage, …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

UISearchBar is a rounded text field which a search icon.

Examples of some UISearchBars. Top: having custom backgroundImage, contentInset and modified cancelButton. Bottom: usesEmbeddedAppearance

More control on appearance

The SDK only provides methods to change the search bar's tint color, but there are undocumented methods for stronger controls.


Signature @property(nonatomic,assign) BOOL usesEmbeddedAppearance;
Available in 3.0 –

Setting this property to true will make the search bar appear as embedded, like within MobileMail.


Signature @property(nonatomic,retain) UIImage* backgroundImage;
Available in 3.0 –

Use this property to set any background for your search bar. Note that the image is always scaled, even if you make a stretched copy.


Signature @property(nonatomic,assign) UIEdgeInsets contentInset;
Available in 3.0 –

Set the padding between the text field and the background. Default is {0, 5, 0, 5}.

cancelButton, searchField

Signature @property(nonatomic,retain) UINavigationButton* cancelButton;
Available in 3.0 –
Signature @property(nonatomic,readonly) UITextField* searchField;
Available in 3.0 –

The cancel button and the text field can also be customized. In particular, the searchField's rightView is that bookmark button, which you can replace with your own.