I want to set title to tab item programatically, but it not works. My code is below:
- (IBAction)tab1Click:(id)sender {
myTabBarController = [[UITabBarContro
You can set all the UITabBar icons in an easy way. You can do this in your viewWillAppear:
method:
[[self.tabBarController.tabBar.items objectAtIndex:0] setTitle:NSLocalizedString(@"BotonMapas", @"comment")];
[[self.tabBarController.tabBar.items objectAtIndex:1] setTitle:NSLocalizedString(@"BotonRA", @"comment")];
[[self.tabBarController.tabBar.items objectAtIndex:2] setTitle:NSLocalizedString(@"BotonEstado", @"comment")];
[[self.tabBarController.tabBar.items objectAtIndex:3] setTitle:NSLocalizedString(@"LabelInfo", @"comment")];
Swift 3.1 Solution
self.tabBarController?.tabBar.items?[0].title = NSLocalizedString("BotonMapas", comment: "comment")
self.tabBarController?.tabBar.items?[1].title = NSLocalizedString("BotonRA", comment: "comment")
self.tabBarController?.tabBar.items?[2].title = NSLocalizedString("BotonEstado", comment: "comment")
self.tabBarController?.tabBar.items?[3].title = NSLocalizedString("LabelInfo", comment: "comment")
If you are calling this from within an embedded UIViewController, you can change the parent tab bar title with:
self.tabBarController.title = @"My Title.";
[view2Controller setTitle:@"ImATitle"];
might be what your after
edit: ok i just tested this and it def works for me so give it a go
UINavigationController *nav1 = [[UINavigationController alloc] init];
myViewController *myView = [[myViewController alloc] init];
//myView.title = @"Title"; //prob not needed
[nav1 pushViewController: myView animated:NO];
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Title" image:[UIImage imageNamed:@"title.png"] tag:0];
nav1.tabBarItem = item;
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = [NSArray arrayWithObjects:nav1, nil];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UITabBarController *tb=[[UITabBarController alloc]init];
UIStoryboard *sb=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc1=[sb instantiateViewControllerWithIdentifier:@"View1"];
UIViewController *vc2=[sb instantiateViewControllerWithIdentifier:@"View2"];
//To Set Title for UIViewController
[vc1 setTitle:@"View1"];
[vc2 setTitle:@"View2"];
NSArray *vController=[[NSArray alloc]initWithObjects:vc1,vc2,nil];
tb.viewControllers=vController;
self.window.rootViewController=tb;
[self.window makeKeyAndVisible];
return YES;
}