Set UITabBarController Items titles while launching the application

DeZigny picture DeZigny · Jul 19, 2011 · Viewed 8.2k times · Source

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

Answer

alex picture alex · Aug 15, 2011

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.