我想设置标题选项卡项编程,但它不起作用。我的代码如下:
- (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;
}发布于 2012-09-25 15:47:42
你可以用一种简单的方式设置所有的UITabBar图标。您可以在viewWillAppear:方法中执行此操作:
[[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解决方案
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")发布于 2012-09-26 23:16:28
如何在实际的View Controller (而不是App Delegate)中执行此操作:
// 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发布于 2012-01-19 22:21:12
一种简单的方法是:在viewController2的viewDidLoad方法中设置self.title = @"MyTitle";
https://stackoverflow.com/questions/8925950
复制相似问题