小编oma*_*rc7的帖子

UISearchBar无法显示正确的tintColor

如果我添加UISearchBar而不将其引用到UISearchDisplayController,则我的tintColor将正确显示。

UISearchBar具有正确的tintColor

searchBar.barTintColor = [UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f];
Run Code Online (Sandbox Code Playgroud)

但是,如果我将我的UISearchBar引用到UISearchDisplayController,则颜色似乎有所不同...

UISearchBar引用了带有错误的tintColor的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;
Run Code Online (Sandbox Code Playgroud)

我在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 …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch uisearchbar uisearchdisplaycontroller ios

1
推荐指数
1
解决办法
2689
查看次数