Граница не очень хорошо меняется с цветом оттенка, поэтому мой дизайнер настаивал на том, чтобы мы изменили его. Это так же просто, как добавление 1px вида внизу панели поиска:
Теперь в viewDidLoad я создаю 1-пиксельное представление и размещаю его в самом низу нашей панели поиска.
#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];
}
Теперь я также возвращаю цвет оттенка к значению по умолчанию, когда пользователь на самом деле выполняет поиск, поскольку подкрашивание строки поиска также окрашивает цвет кнопки отмены в уродливый цвет. Если вы делаете что-то подобное, код ниже будет скрывать / показывать вашу границу для каждого штата:
- (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];
}