简体   繁体   English

如何设置uitoolbar的背景类似于我的导航栏

[英]how to set uitoolbar's background similar to my navigation bar

Hello everyone: 大家好:
I have set a custom background for my navigation bar, it's a tint color i think that i chose from IB. 我为我的导航栏设置了一个自定义背景,它是一种淡色,我认为我选择了IB。 Now i want to change the my uitoolbar's (added programmatically) background similar to my navigation bar, programmatically. 现在我想以编程方式更改我的uitoolbar(以编程方式添加)背景,类似于我的导航栏。 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 :) 感谢你们所有人的快速反应,尤其是@phooze让我朝着正确的方向前进:)

UIToolbar also has a tintColor property, just like a UINavigationBar. UIToolbar也有一个tintColor属性,就像UINavigationBar一样。 You should be able to set one to the other: 你应该可以设置一个到另一个:

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 . 请记住,此代码仅在从NIB加载myNavBar时才有效,因此最好将其放在viewWillAppear:viewDidLoad

You can access the UINavigationBar from the navigationBar property of UINavigationController (probably s elf.parentViewController in your case). 您可以从UINavigationController的navigationBar属性访问UINavigationBar(在您的情况下可能是s elf.parentViewController )。

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];

我使用了以下setBarTintColor,它对我有效,而setTintColor没有。

If you want the default black color for toolbar than you can use 如果您想要工具栏的默认黑色,则可以使用

UIToolbar *ta;
[ta setBarStyle:UIBarStyleBlack];

Only use following code for that..it's working.. 只使用以下代码... ..的工作..

toolbar.tintColor = self.navigationController.navigationBar.tintColor; toolbar.tintColor = self.navigationController.navigationBar.tintColor;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM