how to set uitoolbar's background similar to my navigation bar

Tobias picture Tobias · Feb 16, 2011 · Viewed 15k times · Source

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

Answer

makdad picture makdad · Feb 16, 2011

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