Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set UITabBarController Items titles while launching the application

I have UITabBarController with 5 tabs, how can I set tabs titles while launching the application? The reason behind this is because I want to display tabs titles based on system language (English or Spanish for example)

Regards

like image 327
DeZigny Avatar asked Dec 06 '22 20:12

DeZigny


1 Answers

Setting the tabbar's titles is pretty easy:

This sets up a tabbarcontroller programmatically in your app delegate's applicationDidFinishLaunching method. It is assumed you have all viewcontrollers put in the viewControllers array. You may skip that section, if you have set up your tabbarcontroller via ib.

UITabBarController *tabBarController = [[[UITabBarController alloc] init] retain];
tabBarController.delegate = self;
[tabBarController setViewControllers:viewControllers animated:NO];
tabBarController.selectedIndex = 0;

You may set the titles by:

[[tabBarController.tabBar.items objectAtIndex:0] setTitle:@"title A"];
[[tabBarController.tabBar.items objectAtIndex:1] setTitle:@"title B"];
[[tabBarController.tabBar.items objectAtIndex:2] setTitle:@"title C"];

When it comes to multilingual projects, have a look here. Put all your localized strings into plist files and start with iOS' localization methods. Once started, it is very handy.

like image 146
alex Avatar answered Apr 17 '23 04:04

alex