xcode 如何设置uitoolbar的背景类似于我的导航栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5014085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to set uitoolbar's background similar to my navigation bar
提问by Tobias
Hello everyone:
I have set a custom background for my navigation bar, it's a tint color i think that i chose from IB. Now i want to change the my uitoolbar's (added programmatically) background similar to my navigation bar, programmatically. Obliged for any help in this regard.
大家好:
我为我的导航栏设置了自定义背景,我认为这是一种我从 IB 中选择的色调。现在我想以编程方式更改类似于我的导航栏的 uitoolbar(以编程方式添加的)背景。有义务在这方面提供任何帮助。
Sorry guys my bad it's actually navigation controller's toolbar. so this worked for me:self.navigationController.toolbar.tintColor=self.navigationController.navigationBar.tintColor;
对不起,我不好,它实际上是导航控制器的工具栏。所以这对我有用:self.navigationController.toolbar.tintColor=self.navigationController.navigationBar.tintColor;
Thanks all of u guys for quick response especially @phooze which set me in the right direction :)
感谢你们所有人的快速回复,尤其是@phooze,它让我朝着正确的方向前进:)
回答by makdad
UIToolbar also has a tintColor
property, just like a UINavigationBar. You should be able to set one to the other:
UIToolbar 也有一个tintColor
属性,就像 UINavigationBar 一样。您应该能够将一个设置为另一个:
myToolbar.tintColor = myNavBar.tintColor;
after you create your toolbar. Keep in mind that this code would only work if myNavBar had been loaded from the NIB, so it would be best to put this in viewWillAppear:
or viewDidLoad
.
创建工具栏后。请记住,此代码仅在 myNavBar 已从 NIB 加载时才有效,因此最好将其放入viewWillAppear:
或viewDidLoad
。
You can access the UINavigationBar from the navigationBar
property of UINavigationController (probably self.parentViewController
in your case).
您可以从 UINavigationController 的navigationBar
属性访问UINavigationBar (elf.parentViewController
在您的情况下可能是 s )。
回答by Pankaj Kainthla
There no way to compare the colors of navigation bar and tool bar but you can set toolbar color with following code
无法比较导航栏和工具栏的颜色,但您可以使用以下代码设置工具栏颜色
aToolbar.barStyle = UIBarStyleBlackTranslucent;
aToolbar.tintColor = [UIColor blackColor];
aToolbar.alpha = 0.7;
or
或者
aToolBar.tintColor = [UIColor colorWithRed:0.15 green:0.35 blue:0.45 alpha:0.6];
回答by Girish K Gupta
I used the following setBarTintColor which worked for me while setTintColor didn't.
我使用了以下 setBarTintColor ,它对我有用,而 setTintColor 没有。
回答by Robin
If you want the default black color for toolbar than you can use
如果您想要工具栏的默认黑色,那么您可以使用
UIToolbar *ta;
[ta setBarStyle:UIBarStyleBlack];
回答by dipen chudasama
Only use following code for that..it's working..
只使用以下代码..它的工作..
toolbar.tintColor = self.navigationController.navigationBar.tintColor;
toolbar.tintColor = self.navigationController.navigationBar.tintColor;