如何设置 uitoolbar 的背景类似于我的导航栏
大家好:
我为我的导航栏设置了一个自定义背景,我认为这是我从 IB 选择的色调。现在我想以编程方式更改我的 uitoolbar 的(以编程方式添加)背景,类似于我的导航栏。有义务在这方面提供任何帮助。
对不起大家,我的错,它实际上是导航控制器的工具栏。所以这对我有用:self.navigationController.toolbar.tintColor=self.navigationController.navigationBar.tintColor;
感谢大家的快速回复,特别是@phooze,它让我找到了正确的方向:)
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.
Sorry guys my bad it's actually navigation controller's toolbar. so this worked for me: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 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
UIToolbar 也有一个
tintColor
属性,就像 UINavigationBar 一样。您应该能够将其中之一设置为另一个:创建工具栏后。请记住,只有从 NIB 加载 myNavBar 时,此代码才有效,因此最好将其放在
viewWillAppear:
或viewDidLoad
中。您可以从 UINavigationController 的
navigationBar
属性访问 UINavigationBar(在您的情况下可能是 self.parentViewController
)。UIToolbar also has a
tintColor
property, just like a UINavigationBar. You should be able to set one to the other: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:
orviewDidLoad
.You can access the UINavigationBar from the
navigationBar
property of UINavigationController (probably self.parentViewController
in your case).无法比较导航栏和工具栏的颜色,但您可以使用以下代码设置工具栏颜色
或
There no way to compare the colors of navigation bar and tool bar but you can set toolbar color with following code
or
我使用了以下 setBarTintColor ,它对我有用,而 setTintColor 没有。
I used the following setBarTintColor which worked for me while setTintColor didn't.
如果您想要工具栏的默认黑色,则可以使用
If you want the default black color for toolbar than you can use
仅使用以下代码..它正在工作..toolbar.tintColor
= self.navigationController.navigationBar.tintColor;
Only use following code for that..it's working..
toolbar.tintColor = self.navigationController.navigationBar.tintColor;