how to set uitoolbar's background similar to my navigation bar
Asked Answered
C

5

6

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 :)

Chlorenchyma answered 16/2, 2011 at 8:23 Comment(0)
S
11

UIToolbar also has a tintColor property, just like a 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.

You can access the UINavigationBar from the navigationBar property of UINavigationController (probably self.parentViewController in your case).

Spalato answered 16/2, 2011 at 8:30 Comment(2)
I've already tried this phooze.. not working out in my case. I am doing this in my viewWillAppear: self.toolbar.tintColor = self.navigationController.navigationBar.tintColor;Chlorenchyma
Can you confirm at that point in code that both items are non-nil?Spalato
H
2

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];
Hangover answered 16/2, 2011 at 8:31 Comment(1)
You're correct that it's not possible to compare colors as far as I know, but you can pass around UIColor objects if you already have one (see my answer above).Spalato
B
1

I used the following setBarTintColor which worked for me while setTintColor didn't.

Brune answered 10/4, 2014 at 11:40 Comment(0)
M
0

If you want the default black color for toolbar than you can use

UIToolbar *ta;
[ta setBarStyle:UIBarStyleBlack];
Mellifluent answered 16/2, 2011 at 8:34 Comment(0)
H
0

Only use following code for that..it's working..

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

Howarth answered 15/7, 2011 at 13:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.