0

I had added a tab bar in my application dynamically as shown below:-

 if (isLogin == TRUE) {

        rootController = [[SettingsViewController alloc] init];
        tabTitle = @"Settings";    
        navTitle = @"Settings";
        tabImage = [UIImage imageNamed:@"icon1.png"];

 } 
 else
 {

        root =TRUE;
        rootController = [[RootViewController alloc] init];
        tabTitle = @"Home";    
        navTitle = @"Login";
        tabImage = [UIImage imageNamed:@"icon1.png"];
 }

 break;

 case 1:
    rootController = [[AboutUs alloc] init];
    tabTitle = @"AboutUs";    
    navTitle = @"AboutUs";
    tabImage = [UIImage imageNamed:@"icon2.png"];    
    break;          
 case 2:
    rootController = [[ContactUsViewController alloc] init];
    tabTitle = @"Contact Us";    
    navTitle = @"Contact Us";
    tabImage = [UIImage imageNamed:@"icon3.png"];    
    break;          
 case 3:
    rootController = [[MoreViewController alloc] init];
    tabTitle = @"More";    
    navTitle = @"More";
    tabImage = [UIImage imageNamed:@"icon4.png"];    
    break;

 rootController.view.hidden = FALSE;
 UINavigationController *subController = [[UINavigationController alloc]
 initWithRootViewController:rootController];
 subController.navigationBar.tintColor = [UIColor colorWithRed:(110.0/255.0) green:(184.0/255.0) blue:(71.0/255.0) alpha:1.0];
 subController.navigationBar.topItem.title = navTitle;              
 subController.title = tabTitle;
 subController.navigationItem.hidesBackButton =YES;
 subController.tabBarItem.image = tabImage;
 NSLog(@"%@",subController);

 [controllers addObject:subController];
 NSLog(@"%@",controllers);
 [subController release];       
 [rootController release];

As a result it is showing the tab as below form:-

enter image description here

But I want to cutomise the default detected color of tab bar(Blue color) into orange and want tab bar to look like this:-

enter image description here

Please help me; how can I do this?

Rahul
  • 12,886
  • 13
  • 57
  • 62
ios developer
  • 3,363
  • 3
  • 51
  • 111

5 Answers5

2

You can change tab bar color and many apps approved in apple. You can subclass UITabBar and change the color as you want. In your case you need to subclass UITabBarItem. Here is a stackoverflow post have a look Custom colors in UITabBar

Community
  • 1
  • 1
Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256
  • thanks for the reply.I had added the above(mine code) in my appdelegate method as i want this tab bar to work in my whole application and i had checked ur reply but it doest work.Please can u explain me in detail how to do it.Or can show me the other way to do it.Please help me – ios developer Jun 22 '11 at 06:26
  • @shweta read this post carefully http://blog.theanalogguy.be/2010/10/06/custom-colored-uitabbar-icons/ – Rahul Vyas Jun 22 '11 at 07:04
0

In AppDelegete.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];
return YES;
}
Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
0

You can also try to change tabbar icon image instead of changing color,

like.

in tabbar controller delegate method

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

{
    if([tabBarController selectedIndex] == 0)
    {
        [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
    }    
}

through this you can change your tabbaritem image.

Or you can use directly in your view controllers init(or ViewWillAppear) method, like

        [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
Muhammad Rizwan
  • 3,470
  • 1
  • 27
  • 35
0

If it was not allowed to customize the tab bar, then Apple would break their own guidelines with their own Game Center app (of which the design looks very nice btw)

Sfynx
  • 365
  • 2
  • 4
-1

You cannot change the default color of tabbar. This is one of the User interface guidelines we have to follow in iOS applications.

I had commented on this question when it was not possible to change default color for tab bar. Now we can change default color of tab bar.

Swapna
  • 2,245
  • 2
  • 19
  • 22