【问题标题】:UISearchBar not displaying correct tintColorUISearchBar 未显示正确的 tintColor
【发布时间】:2014-06-21 09:21:42
【问题描述】:

如果我添加我的 UISearchBar 而不将它引用到 UISearchDisplayController,我的 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

提前致谢!

【问题讨论】:

    标签: ios cocoa-touch uisearchbar uisearchdisplaycontroller


    【解决方案1】:

    您可以在搜索器中设置图像。它适用于搜索栏。

    [[UISearchBar appearance] setBackgroundImage:[UIImage imageNamed:@"red"]];
    

    【讨论】:

    • 效果很好,现在我只是想找到一种方法在背景中显示相同的颜色以进行过渡。
    【解决方案2】:

    尝试将半透明属性设置为 no。

    [[UISearchBar appearance] setTranslucent:NO];
    

    【讨论】:

      【解决方案3】:

      我发现该解决方案适用于 iOS7+

      searchBar.backgroundImage = UIImage()
      searchBar.tintAdjustmentMode = UIViewTintAdjustmentMode.Normal
      searchBar.barTintColor = Utils.tintColor()
      

      【讨论】:

        【解决方案4】:

        对于 Swift 中的 UISearchController 使用:

        searchController.searchBar.barTintColor = UIColor.whiteColor()
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-10-03
          • 2012-06-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多