在UISearchBar上将半透明设置为NO [英] Setting translucent to NO on UISearchBar

查看:155
本文介绍了在UISearchBar上将半透明设置为NO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个 UITableView ,其中搜索栏添加了 searchDisplayController

We have a UITableView with a searchbar added with the searchDisplayController.

我们想要在整个应用程序中关闭半透明效果。

We want to have translucency off throughout the app.

我对导航栏有半透明效果其他栏,但使用显示控制器时不是搜索栏。在我们使用搜索栏而不是显示控制器的应用程序的一部分中,半透明度设置正确。

I have the translucency off for the navigation bar and other bars, but not the search bar when it uses the display controller. In one part of the app when we use the search bar but not the display controller, the translucency is set correctly.

如何设置<$的半透明属性c $ c> UISearchBar 显示控制器是NO?

How can I set the translucent property of the UISearchBar with the display controller to be NO?

编辑:
这是我在<$ c $中的代码c> viewDidLoad

self.navigationController.navigationBar.translucent = NO;
BOOL t = self.searchDisplayController.searchBar.translucent;
self.searchDisplayController.searchBar.translucent = NO;
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
self.searchDisplayController.searchBar.barTintColor = [UIColor redColor];
UIBarStyle b1 = self.searchDisplayController.searchBar.barStyle;
UISearchBarStyle b2 = self.searchDisplayController.searchBar.searchBarStyle;
BOOL t2 = self.searchDisplayController.searchBar.translucent;

在调试器中运行,t = YES,t2 = YES。 b1 = UIBarStyleDefault 和b2 = UISearchBarStyleDefault 。我在错误的地方设置NO吗?我已经尝试了故事板中的设置,并在 viewDidLoad

Running in the debugger, t = YES and t2 = YES. b1 = UIBarStyleDefault and b2 = UISearchBarStyleDefault. Am I setting NO at the wrong spot? Ive tried the setting in the storyboard and here in viewDidLoad

推荐答案

对于UISearchBarStyleProminent:

1)请务必选中半透明复选框属性检查器中的搜索栏。

1) Be sure to check the "Translucent" box for the search bar in the Attributes Inspector.

2)将以下内容添加到viewDidLoad:

2) Add the following to viewDidLoad:

self.navigationController.navigationBar.translucent = NO; // If you have a navBar
self.searchDisplayController.searchBar.translucent = NO;

编辑来自 @RudolfAdamkovic


我发现 UISearchBarStyleProminent ,执行[以下]帮助。这样,你可以在故事板中保持它。

searchBar.translucent = YES;

searchBar.translucent = NO;

"I've found that for UISearchBarStyleProminent, executing [the following] helps. That way, you can keep it on in Storyboard."
searchBar.translucent = YES;
searchBar.translucent = NO;

对于UISearchBarStyleMinimal:

为了让最小的搜索栏不是半透明的,我已经整理了一个解决方法。

In order to get the minimal search bar to not be translucent I have put together a workaround.

1)请务必检查属性检查器中搜索栏的半透明框。

1) Be sure to check the "Translucent" box for the search bar in the Attributes Inspector.

2 )将以下代码添加到viewDidLoad:

2) Add the following code to viewDidLoad:

self.navigationController.navigationBar.translucent = NO;
self.searchDisplayController.searchBar.translucent = NO;
self.searchDisplayController.searchBar.backgroundColor = [UIColor desiredColor];

3)需要将UIView添加到viewController中。此视图需要为20px高度,并且应与searchBar.barTintColor具有相同的颜色。

3) A UIView needs to be added to the viewController. This view needs to be 20px heigh and should have the same color as the searchBar.barTintColor.

注意:我认为此解决方法是必需的,因为:样式UISearchBarStyleMinimal不提供默认的背景颜色或图像,但如果自定义则显示一个。因此,为UISearchBarStyleMinimal获取此功能的唯一方法是设置backgroundColor。

Note: I think this workaround is needed because: "The style UISearchBarStyleMinimal provides no default background color or image but will display one if customized as such." Thus the only way to get this functionality for UISearchBarStyleMinimal is to set the backgroundColor.

请参阅UISearchBar 文档了解更多详情。

See UISearchBar documentation for more details.

这篇关于在UISearchBar上将半透明设置为NO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆