R – Showing UISearchBar “X” within text field vs. adjacent Cancel button

cancel-buttoniphone-sdk-3.0uikituisearchbaruisearchdisplaycontroller

I know I can set showsCancelButton to NO for a UISearchBar … until you tap the search bar text field, and then the cancel button appears anyway! (At least it does for me.)

Is there a way to show the "X" in a circle within the UISearchBar text field vs. having that separate Cancel button show up adjacent to it? Note that this button only appears for me when search mode is active, and this is regardless of the setting for showsCancelButton.

Best Answer

try this

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    // only show the status bar's cancel button while in edit mode
    mySearchBar.showsCancelButton = NO;

}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
    mySearchBar.showsCancelButton = NO;
}

when using this cancel button will not shown.