Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set tab bar item title programmatically in objective c?

I want to set title to tab item programatically, but it not works. My code is below:

- (IBAction)tab1Click:(id)sender {     myTabBarController = [[UITabBarController alloc] init];             view2Controller = [[View2Controller alloc] init];      [view2Controller setTitle:@"title"];     view3Controller = [[View3Controller alloc] init];       deneme = [[ViewController alloc] init];        myTabBarController.viewControllers = [NSArray arrayWithObjects:deneme, view2Controller,view3Controller, nil];      [self.view addSubview:myTabBarController.view];         myTabBarController.selectedIndex=1; } 
like image 905
Hacer sengul Akac Avatar asked Jan 19 '12 12:01

Hacer sengul Akac


People also ask

How do I add icons to my tab bar controller?

Marquee select all three controllers, and then from the menu bar select Editor>Embed> Tab Bar controller. All three are now in the tab bar controller, which I'll spread out a little. Zoom to the bottom of the tab bar controller and you'll see the three icons I already added to this project.

How do I add an image to the tab bar in iOS?

iOS UITabBarController Changing Tab Bar Item Title and Icon For a custom icon, add the required images to the assets folder and set the 'System Item' from earlier to 'custom'. Now, set the icon to be shown when the tab is selected from the 'selected image' drop down and the default tab icon from the 'image' drop down.


1 Answers

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") 
like image 71
Aitul Avatar answered Sep 30 '22 08:09

Aitul