【问题标题】:UISearchBar and UISearchDisplayController background colorUISearchBar 和 UISearchDisplayController 背景颜色
【发布时间】:2015-04-23 09:22:05
【问题描述】:

我在导航栏中添加了一个UISearchBar,当用户点击某个按钮时,它就会显示出来。另外,我以编程方式链接了UISearchDisplayController。搜索栏的背景颜色是透明的。

我的问题是,当黑色半透明覆盖被点击并且UISearchDisplayController 变为非活动状态时,我看到一个非常丑陋的搜索栏动画:它拉伸到全尺寸(不再显示取消按钮)并应用某种 o灰色背景。

当用户点击取消按钮以使UISearchDisplayController 变为非活动状态时,一切都很好。

有人可以解决我的问题吗?

谢谢。

【问题讨论】:

标签: ios uisearchbar uisearchdisplaycontroller uisearchcontroller


【解决方案1】:

您可以制作自定义背景图片:

[searchBar setBackgroundImage:[UIImage imageNamed:@"searchBarBackground"]];
[searchBar setScopeBarBackgroundImage:[UIImage imageNamed:@"searchBarBackground"]];
[searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"searchFieldBackgroundImage"] forState:UIControlStateNormal];

搜索栏背景

setSearchFieldBackgroundImage - 透明图片

【讨论】:

    【解决方案2】:

    因为我使用的是 UIViewController+MMDrawerController.h,所以设置 UISearchDisplayController 的正确方法是:

    [[UISearchDisplayController alloc] initWithSearchBar:search
                                      contentsController:self.mm_drawerController.centerViewController];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-20
      • 2020-02-07
      • 1970-01-01
      • 1970-01-01
      • 2017-06-08
      相关资源
      最近更新 更多