1

I have a UITabbar controller with 3 item, I want to have colour icon instead of based Gary icons,

would you please give me some hint that how can I have colour icon in tababr,

Here is my code:

self.title = @"test";

   self.tabBarItem = [[UITabBarItem alloc] initWithTitle:self.title image:[UIImage 
 imageNamed:@"test"] tag:0];

normally test is a icone with a colour picture, but in UITabbar it's just Gary,

Thanks in advance!

  • possible duplicate of [How to change default the gray color of uitabbaritem in uitabbarcontroller?](http://stackoverflow.com/questions/4604555/how-to-change-default-the-gray-color-of-uitabbaritem-in-uitabbarcontroller) – Anoop Vaidya Mar 25 '13 at 03:38

3 Answers3

4

Use this code:

[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"test"] 
withFinishedUnselectedImage:[UIImage imageNamed:@"test"]];
Elnaz
  • 1,095
  • 1
  • 12
  • 30
0

You will need to build your own TabBarController. As Per the Apple docs on the matter "This class [UITabBarController] is not intended for subclassing". The docs on the UITabBarItem say that when you are supplying an image for the tab bar "The images displayed on the tab bar are derived from this image". So, whatever image you provide to the tab bar will get manipulated to make it conform to the "normal" look of a tab bar image.

So, you can build a UIViewController with some UIButtons as subviews and then manage the entire look and feel that way.

Dipen Panchasara
  • 13,480
  • 5
  • 47
  • 57
0

you have to create 2 images for all 3 tabs one is unselected and second is selected.

after that in your appdelegate.m file write below code

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
       self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
       // Override point for customization after application launch.
       self.searchArray = [[NSMutableArray alloc]init];
       self.tabBarController = [[[UITabBarController alloc] init] autorelease];

       viewController1 *view1 = [[[viewController1 alloc] initWithNibName:@"viewController1" bundle:nil] autorelease];
       view1.tabBarItem.image = [UIImage imageNamed:@"tab-selected-1"];
       view1.tabBarItem.title = @"Title1";           

       viewController2 *view2 = [[[viewController2 alloc] initWithNibName:@"viewController2" bundle:nil] autorelease];
       view2.tabBarItem.image = [UIImage imageNamed:@"tab-selected-2"];
       view2.tabBarItem.title = @"Title2";

       viewController3 *view3 = [[[viewController3 alloc] initWithNibName:@"viewController3" bundle:nil] autorelease];
       view3.tabBarItem.image = [UIImage imageNamed:@"tab-selected-3"];
       view3.tabBarItem.title = @"Title3";



       self.tabBarController.viewControllers = [NSArray arrayWithObjects:view1, view2, view3, nil];

       UITabBarItem *tabBarItem1 = [[self.tabBarController.tabBar items] objectAtIndex:0];
       [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"tab-selected-1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab-unselected-1.png"]];


       UITabBarItem *tabBarItem2 = [[self.tabBarController.tabBar items] objectAtIndex:1];
       [tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"tab-selected-2.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab-unselected-2.png"]];

       UITabBarItem *tabBarItem3 = [[self.tabBarController.tabBar items] objectAtIndex:2];
       [tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"tab-selected-3.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab-unselected-3.png"]];


       return YES;
}

try this your problem surly solved. Best Of Luck

Pratik
  • 2,399
  • 17
  • 36