Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set a separate short title for UITabBar?

I'd like to be able to give my views short names for display on the tab bar, and longer (more descriptive) name when the same view is linked to in a table view. The reason is that longer names nudge up against each other on the tab bar. In a table view, there's more horizontal space, so I want to use more descriptive titles there.

Normally, the tab bar's title is set in its view controller with self.title. Is there a way to specifically set the tab bar title, but leave the view controller's self.title alone?

Thanks.

like image 258
nevan king Avatar asked Sep 07 '09 09:09

nevan king


2 Answers

The information that is displayed in a UITabBar is queried from each UIViewController's tabBarItem" property. Similarly, a UINavigationBar queries the UIViewController's navigationItem for information.

Setting two different titles would work like this (from within you UIViewController):

self.tabBarItem.title = @"TabTitle";
self.navigationItem.title = @"NavigationTitle";

You can also specify other details like the tab bar image or the title on the "back button" via these properties.

like image 116
rluba Avatar answered Sep 27 '22 20:09

rluba


Short and sweet, in your view controller's viewDidLoad:

[[self tabBarItem] setTitle:@"Short Title"];
like image 36
iKenndac Avatar answered Sep 27 '22 20:09

iKenndac