如果我在没有将其引用到UISearchDisplayController的情况下添加我的UISearchBar,我的tintColor会正确显示。
searchBar.barTintColor = [UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f];
但是,如果我将我的UISearchBar引用到UISearchDisplayController,颜色似乎不同......
searchBar = [[UISearchBar alloc] init];
[searchBar setBarTintColor:[UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f]];
searchBar.delegate = self;
searchBar.searchBarStyle = UISearchBarStyleProminent;
searchBar.placeholder = @"Buscar restaurantes o platillos";
searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
self.tableView.tableHeaderView = searchBar;
我的AppDelegate上的tintColor设置是
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
[[UIToolbar appearance] setBarTintColor:[UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f]];
self.window.tintColor = [UIColor whiteColor];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.backgroundColor = [UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f];
除此之外,当我的UISearchBar被引用到我的UISearchDisplayController并点击搜索字段时......在转换时,状态栏的背景为白色。
有什么想法吗?
我正在使用iOS7
提前致谢!
答案 0 :(得分:4)
您可以在搜索器中设置图像。它适用于搜索栏。
[[UISearchBar appearance] setBackgroundImage:[UIImage imageNamed:@"red"]];
答案 1 :(得分:1)
尝试将半透明属性设置为no。
[[UISearchBar appearance] setTranslucent:NO];
答案 2 :(得分:1)
我发现该解决方案适用于iOS7 +
searchBar.backgroundImage = UIImage()
searchBar.tintAdjustmentMode = UIViewTintAdjustmentMode.Normal
searchBar.barTintColor = Utils.tintColor()
答案 3 :(得分:1)
对于 Swift 中的 UISearchController ,请使用:
searchController.searchBar.barTintColor = UIColor.whiteColor()