首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在objective c中以编程方式设置选项卡栏项目标题?

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

Stack Overflow用户
提问于 2012-01-19 20:22:25
回答 10查看 66.3K关注 0票数 37

我想设置标题选项卡项编程,但它不起作用。我的代码如下:

代码语言:javascript
运行
复制
- (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;
}
EN

回答 10

Stack Overflow用户

发布于 2012-09-25 15:47:42

你可以用一种简单的方式设置所有的UITabBar图标。您可以在viewWillAppear:方法中执行此操作:

代码语言:javascript
运行
复制
[[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解决方案

代码语言:javascript
运行
复制
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")
票数 66
EN

Stack Overflow用户

发布于 2012-09-26 23:16:28

如何在实际的View Controller (而不是App Delegate)中执行此操作:

代码语言:javascript
运行
复制
// set tab title
self.title = @"Tab Title";
// optionally, set different title for navigation controller
self.navigationItem.title = @"Nav Title";
// Note: self.title will reset Nav Title. Use it first if you want different titles
票数 29
EN

Stack Overflow用户

发布于 2012-01-19 22:21:12

一种简单的方法是:在viewController2viewDidLoad方法中设置self.title = @"MyTitle";

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8925950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档