Domanda

I want to implement uitab bar,which is the best and less hectic way to implement it?

È stato utile?

Soluzione

i don't know you want like this or not but i am doing this way in all projects..

- (void)viewDidLoad
{
   [self setmenu];
}
-(void)setmenu:(id)sender
{
UIImage *tabBackground = [[UIImage imageNamed:@"tabbg.png"]
                          resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];

UIColor *titleHighlightedColor = [UIColor whiteColor];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   titleHighlightedColor, UITextAttributeTextColor,
                                                   nil] forState:UIControlStateSelected];

[[UITabBarItem appearance] setTitleTextAttributes:@{UITextAttributeFont:[UIFont systemFontOfSize:12], UITextAttributeTextColor:[UIColor colorWithRed:59.0/255.0f green:59.0/255.0f blue:59.0/255.0f alpha:1.0f]}  forState:UIControlStateNormal];


UITabBarItem *tabBarItem1 = [theTabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [theTabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [theTabBar.items objectAtIndex:2];

tabBarItem1.title  =[appDelegate.dict objectForKey:@"One"];
tabBarItem2.title = [appDelegate.dict objectForKey:@"Two"];
tabBarItem3.title = [appDelegate.dict objectForKey:@"Three"];

[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"one_active.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"one.png"]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"two_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"two.png"]];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"three_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"three.png"]];

[theTabBar setSelectedItem:[theTabBar.items objectAtIndex:0]];

UIImage *tabBackground1 = [[UIImage imageNamed:@"tabbg_active.png"]
                           resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setSelectionIndicatorImage:tabBackground1];
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if([item.title isEqual: [appDelegate.dict objectForKey:@"One"]])
{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
    One *mvc = [sb instantiateViewControllerWithIdentifier:@"One"];
    [self.navigationController pushViewController:mvc animated:YES];
}
else if([item.title isEqual: [appDelegate.dict objectForKey:@"Two"]])
{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
    Two *mvc = [sb instantiateViewControllerWithIdentifier:@"Two"];
    [self.navigationController pushViewController:mvc animated:YES];
}
else if([item.title isEqual: [appDelegate.dict objectForKey:@"Three"]])
{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
    Three *mvc = [sb instantiateViewControllerWithIdentifier:@"Three"];
    [self.navigationController pushViewController:mvc animated:YES];
}
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top