如何设置uitoolbar的背景类似于我的导航栏 [英] how to set uitoolbar's background similar to my navigation bar

查看:116
本文介绍了如何设置uitoolbar的背景类似于我的导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:
我为导航栏设置了自定义背景,我认为是从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的背景类似于我的导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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