Illep
Illep

Reputation: 16851

Change the color of tabbar and navigation bar programmatically

The default color of the UITabBarController is black while the default color of the UINavigationController is blue. I need to change this color to some other color. How can I do this programmatically?

I think I found how to change the color of navigation bar but I don't understand the code [navBorder setBackgroundColor:[UIColor colorWithWhite:200.0f/255.f alpha:0.8f]];

I don't understand what colorWithWhite does?

Anyway how do I add color to the UITabBarController?

Upvotes: 1

Views: 5699

Answers (3)

matt
matt

Reputation: 535325

To change the color in iOS 5, set the tintColor of the UITabBarController's tabBar. Here is an example of me doing it:

https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/ch19p533tabBarController/p464p475tabBarController/AppDelegate.m

(You can download that project and try it out for yourself.)

The colorWithWhite:alpha: is a shortcut for setting a grey, possibly with transparency.

Upvotes: 4

Purva
Purva

Reputation: 1291

To change the color of UITabBar programatically you can use tintcolor property the following line of code will help you out

self.navigationController.navigationBar.tintColor= [UIColor redColor];

change the tabbar color

tabBar.tintColor = [UIColor greenColor];

Upvotes: 3

Anil Kothari
Anil Kothari

Reputation: 7733

There is an Appearance Proxy in iOS 5

UIAppearance.h class

@Protocol UIAppearance <NSObject>
+(id) appearance ;
+(id) appearanceWhenContainedIn:(Class <UIAppearanceContainer> containerClass,..)
...

@end

#define UI_APPEARANCE_SELECTOR

This will help you to change the appearance of the controls whichever you want... You can also watch the WWDC 2011 Session Video's "Customizing the appearance of UIKit Controls" for more.

example:-

[[UINavigationBar appeareance] setBackGroundImage:[UIImage imageNamed:@"navBackground"] forBarMetrics:UIBarMetricsDefault];

It changes the navigation bar image to be navBackground image in the application resouce folder and set the navigation bar metrics to be default.

[[UIButton ButtonWhenContainedIn:[CustomViewController Class],[UINavigationController Class],nil] setTitleColor:[UIColor redColor] forControlState:UIControlStateNormal];

It will set button's title color red when contained in this hierarchy.

Upvotes: 1

Related Questions