且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在目标c中以编程方式设置选项卡栏项目标题?

更新时间:2023-02-04 13:30:02

您可以轻松设置所有UITabBar图标.您可以在viewWillAppear:方法中完成此操作:

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解决方案

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")