如何在目标c中以编程方式设置选项卡栏项目标题? [英] How to set tab bar item title programmatically in objective c?
本文介绍了如何在目标c中以编程方式设置选项卡栏项目标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以编程方式将标题设置为选项卡项,但是它不起作用.我的代码如下:
I want to set title to tab item programatically, but it not works. My code is below:
- (IBAction)tab1Click:(id)sender {
myTabBarController = [[UITabBarController alloc] init];
view2Controller = [[View2Controller alloc] init];
[view2Controller setTitle:@"title"];
view3Controller = [[View3Controller alloc] init];
deneme = [[ViewController alloc] init];
myTabBarController.viewControllers = [NSArray arrayWithObjects:deneme, view2Controller,view3Controller, nil];
[self.view addSubview:myTabBarController.view];
myTabBarController.selectedIndex=1;
}
推荐答案
您可以轻松设置所有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")
这篇关于如何在目标c中以编程方式设置选项卡栏项目标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文