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

送分小仙女□ 提交于 2020-01-22 22:56:56

问题


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.


回答1:


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.




回答2:


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

[[self tabBarItem] setTitle:@"Short Title"];


来源:https://stackoverflow.com/questions/1388447/is-there-a-way-to-set-a-separate-short-title-for-uitabbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!