Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The border doesn't seem to change very well with the Tint color, so my designer insisted that we change it. It's as simple as adding a 1px view to the bottom of your search bar:</p> <p>Now in the viewDidLoad, I create a 1px view and position it at the very bottom of our search bar.</p> <pre><code>#define SEARCHBAR_BORDER_TAG 1337 - (void) viewDidLoad{ // Set a custom border on the bottom of the search bar, so it's not so harsh UISearchBar *searchBar = self.searchDisplayController.searchBar; UIView *bottomBorder = [[UIView alloc] initWithFrame:CGRectMake(0,searchBar.frame.size.height-1,searchBar.frame.size.width, 1)]; [bottomBorder setBackgroundColor:[UIColor colorWithWhite:200.0f/255.f alpha:1.0f]]; [bottomBorder setOpaque:YES]; [bottomBorder setTag:SEARCHBAR_BORDER_TAG]; [searchBar addSubview:bottomBorder]; [bottomBorder release]; } </code></pre> <p>Now, I also transition the tint color back to default when the user is actually searching, because tinting the search bar also tints the cancel button color to an ugly color. If you do something similar, the code below will hide/show your border for each state:</p> <pre><code>- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{ [controller.searchBar setTintColor:nil]; // Hide our custom border [[controller.searchBar viewWithTag:SEARCHBAR_BORDER_TAG] setHidden:YES]; } - (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller{ [controller.searchBar setTintColor:[UIColor colorWithRed:238.0f/255.0f green:245.0f/255.0f blue:248.0f/255.0f alpha:1.0f]]; //Show our custom border again [[controller.searchBar viewWithTag:SEARCHBAR_BORDER_TAG] setHidden:NO]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload