我们希望在整个应用程序中保持半透明状态.
我对导航栏和其他栏有半透明效果,但在使用显示控制器时没有搜索栏.在应用程序的一部分,当我们使用搜索栏而不是显示控制器时,半透明度设置正确.
如何在显示控制器为NO的情况下设置UISearchBar的半透明属性?
编辑:
这是我在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中
解决方法
self.navigationController.navigationBar.translucent = NO; // If you have a navBar self.searchdisplayController.searchBar.translucent = NO;
从@RudolfAdamkovic编辑:
“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:
self.navigationController.navigationBar.translucent = NO; self.searchdisplayController.searchBar.translucent = NO; self.searchdisplayController.searchBar.backgroundColor = [UIColor desiredColor];
3)需要将UIView添加到viewController中.此视图需要为20px高度,并且应与searchBar.barTintColor具有相同的颜色.
注意:我认为需要这种解决方法,因为:“The style UISearchBarStyleMinimal provides no default background color or image but will display one if customized as such.”因此,为UISearchBarStyleMinimal获取此功能的唯一方法是设置backgroundColor.
有关详细信息,请参阅UISearchBar documentation.