UItableView和UINavigationBar的UISearchBarController外观错误

时间:2015-12-09 12:03:08

标签: ios objective-c uikit ios9 uisearchbar

我有一个UISearhBarController,其搜索栏位于uiTableView.tableHeaderView中,该视图位于带导航栏的视图中。

我正在为搜索栏设置自定义颜色,如此;

self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
self.searchController.searchBar.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor]];
self.searchController.searchBar.backgroundColor = [UIColor whiteColor];
self.searchController.searchBar.translucent = NO;
self.searchController.searchBar.tintColor = [UIColor ACYellowColor];

我改变颜色,使其在活动时适合导航栏:

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];
self.searchController.searchBar.backgroundImage = [UIImage imageWithColor:[UIColor ACBlackColor]];
self.searchController.searchBar.backgroundColor = [UIColor ACBlackColor];
}

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor blackColor]];
    self.searchController.searchBar.backgroundImage = [UIImage imageWithColor:[UIColor whiteColor]];
    self.searchController.searchBar.backgroundColor = [UIColor whiteColor];
}

有时,当搜索栏处于活动状态时,在旋转时,它将变为灰色。它只在转换为纵向时才会这样做,并且仅在iOS 9上进行。当我不修改searchBarTextDidBeginEditing或searchBarCancelButtonClicked中的颜色时(这样它从白色变为灰色)也会发生这种情况。

这是一个说明问题的video

1 个答案:

答案 0 :(得分:0)

原来是范围栏(我没有使用)。 设置它的背景是明确的问题

self.searchController.searchBar.scopeBarBackgroundImage = [UIImage imageWithColor:[UIColor clearColor]];