问题描述
大家好:
我为导航栏设置了自定义背景,我认为是从IB选择的一种淡色.现在,我想以编程方式更改uitoolbar的背景(以编程方式添加),使其类似于导航栏.有义务在这方面提供任何帮助.
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.
对不起,我不好,它实际上是导航控制器的工具栏.所以这对我有用:self.navigationController.toolbar.tintColor=self.navigationController.navigationBar.tintColor;
Sorry guys my bad it's actually navigation controller's toolbar. so this worked for me:self.navigationController.toolbar.tintColor=self.navigationController.navigationBar.tintColor;
感谢你们所有人的快速响应,特别是@phooze,它使我朝着正确的方向发展:)
Thanks all of u guys for quick response especially @phooze which set me in the right direction :)
推荐答案
UIToolbar也具有tintColor
属性,就像UINavigationBar一样.您应该可以将另一个设置为:
UIToolbar also has a tintColor
property, just like a UINavigationBar. You should be able to set one to the other:
myToolbar.tintColor = myNavBar.tintColor;
创建工具栏后.请记住,此代码仅在myNavBar已从NIB加载的情况下才有效,因此最好将其放在viewWillAppear:
或viewDidLoad
中.
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
.
您可以从UINavigationController的navigationBar
属性(在您的情况下可能是s elf.parentViewController
)访问UINavigationBar.
You can access the UINavigationBar from the navigationBar
property of UINavigationController (probably self.parentViewController
in your case).
这篇关于如何设置uitoolbar的背景类似于我的导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!