0

I'm working on an iOS application and I need to customize the tabbar to be like this:

enter image description here Tabbar Image

A web search gave me this solution:

[self.tabBarItem setFinishedSelectedImage:<#(UIImage *)#> withFinishedUnselectedImage:<#(UIImage *)#>]

But it is for iOS5. Is there a solution that works in both iOS4 and iOS5?

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188

2 Answers2

0

we use the below code.you can customize the tabbar

self.tabBarController = [[UITabBarController alloc]init];
firstClassobj.tabBarItem = [[UITabBarItem alloc]
                     initWithTitle:NSLocalizedString(@"yourtext", @"yourtext)
                     image:[UIImage imageNamed:@"your Image"]
                     tag:0];
secondClassobj.tabBarItem = [[UITabBarItem alloc]
                     initWithTitle:NSLocalizedString(@"yourtext", @"yourtext)
                     image:[UIImage imageNamed:@"your Image"]
                     tag:0];
self.tabBarController .viewControllers = [NSArray arrayWithObjects:firstClassobj,secondClassobj,nil];
Pratyusha Terli
  • 2,343
  • 19
  • 31
kumar
  • 453
  • 1
  • 5
  • 26
  • you need to initialize the viewcontrollers – kumar Nov 06 '12 at 07:47
  • you need to add all view controllers in your array – kumar Nov 06 '12 at 07:47
  • i already intialized them FirstViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; self.firstNav=[[nib instantiateWithOwner:nil options:nil]objectAtIndex:0]; [self.firstNav setViewControllers:[NSArray arrayWithObject:viewController1]]; self.tabBarController = [[UITabBarController alloc] init]; self.firstNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@"tab_btn_members_s0.png"] tag:0]; – mohamed khairy Nov 06 '12 at 07:50
  • self.tabBarController.viewControllers = @[self.firstNav, self.secondNav,self.thirdNav,self.fourthNav,self.fifthNav]; – mohamed khairy Nov 06 '12 at 07:52
  • @mohamedkhairy what's the problem in your view ? – kumar Nov 06 '12 at 07:54
  • @mohamedkhairy it's works fine.initialise the tabbar controller – kumar Nov 06 '12 at 07:55
  • image doesn't appear and tabbar look like this http://postimage.org/image/7suiv9q8j/ – mohamed khairy Nov 06 '12 at 07:57
  • @mohamedkhairy use static images(those are small) and then check – kumar Nov 06 '12 at 07:58
  • use this self.tabBarController.tabBar.tintColor=[UIColor redColor]; – kumar Nov 06 '12 at 08:04
  • what can i do i can;t fix it at all? – mohamed khairy Nov 06 '12 at 08:20
0

//here is the code that i implement successfully.......

//in .h set delegate UITabBarControllerDelegate,UITabBarDelegate

    UINavigationController *navigationController;
    UITabBarController *tabBarController;
    @property(strong,nonatomic) UINavigationController *navigationController;
    @property(strong,nonatomic) UITabBarController *tabBarController;

//in .m

  tabBarController = [[UITabBarController alloc] init];
  [tabBarController setDelegate: self];

//for tabbar background tabBarController.tabBar.tintColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"tabbg.png"]];

NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:4];

Demo1 *home = [[Login alloc] initWithNibName:@"Login" bundle:nil];
    localNavController = [[UINavigationController alloc] initWithRootViewController:home];
localNavController.tabBarItem.title=@"demo1";
[localViewControllersArray addObject:localNavController];
    Demo2 *puck=[[Demo2 alloc]initWithNibName:@"Demo2" bundle:nil];
    localNavController = [[UINavigationController alloc] initWithRootViewController:puck];
localNavController.tabBarItem.title=@"demo2";
[localViewControllersArray addObject:localNavController];
    Demo3 *photo=[[Demo3 alloc]initWithNibName:@"Demo3" bundle:nil];
    localNavController = [[UINavigationController alloc] initWithRootViewController:photo];
localNavController.tabBarItem.title=@"demo3";
    [localViewControllersArray addObject:localNavController];
    Demo4 *more=[[Demo4 alloc]initWithNibName:@"Demo4" bundle:nil];
    localNavController = [[UINavigationController alloc] initWithRootViewController:more];
localNavController.tabBarItem.title=@"demo4";
[localViewControllersArray addObject:localNavController];

  [[UITabBarItem appearance] setTitleTextAttributes:
 [NSDictionary dictionaryWithObjectsAndKeys:
  [UIColor grayColor], UITextAttributeTextColor, 
  [UIColor grayColor], UITextAttributeTextShadowColor, 
  [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
  [UIFont fontWithName:@"Helvetica" size:0.0], UITextAttributeFont, 
  nil] 
                                         forState:UIControlStateNormal];

//tab bar selected and unselected icons

UITabBarItem *tabBarItem1 = [[self.tabBarController.tabBar items] objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"puckCentralA.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"puckCentral.png"]];
UITabBarItem *tabBarItem2 = [[self.tabBarController.tabBar items] objectAtIndex:1];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"puckDisplayA.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"puckDisplay.png"]];
UITabBarItem *tabBarItem3 = [[self.tabBarController.tabBar items] objectAtIndex:2];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"photoBoothA.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"photoBooth.png"]];
UITabBarItem *tabBarItem4 = [[self.tabBarController.tabBar items] objectAtIndex:3];
[tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:@"moreA.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"more.png"]];

[self.window addSubview:tabBarController.view];

Usman
  • 24
  • 6