以编程方式设置UITabBar标题 [英] Programmatically Setting UITabBar Titles

查看:114
本文介绍了以编程方式设置UITabBar标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编程添加tabbar如下所示: -

i had programetically add the tabbar as shown below:-

FirstViewController *obj_FirstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; SecondViewController *obj_SecondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; ThirdViewController *obj_ThirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];

navigation1 = [[UINavigationController alloc] initWithRootViewController:obj_FirstViewController];  
navigation2 = [[UINavigationController alloc] initWithRootViewController:obj_SecondViewController];
navigation3 = [[UINavigationController alloc] initWithRootViewController:obj_ThirdViewController];

MainTabBar = [[UITabBarController alloc] init];
MainTabBar.delegate=self;
[MainTabBar setViewControllers:[NSArray arrayWithObjects:navigation1,navigation2,navigation3,nil]];
MainTabBar.view.frame=self.view.frame;
MainTabBar.selectedIndex=0;
[self.view addSubview:MainTabBar.view]

$ c>(void)viewDidLoad 我有我的viewcontroller的3选项卡。但是问题是我想设置标签的名称为1)首页2)收藏3)关于我们

By writing this in (void)viewDidLoad i got the 3 tab in my viewcontroller. But the problem is i want to set the name of the tab as 1)Home 2)Favorites 3)About us

我试过写下面的代码:

- 1)obj_FirstViewController.tabBarItem.title=@"Home"; 2)self.title = @"My View Controller";

但这不行。任何人都可以帮我如何做这个程序。

But this does not work. Can anyone please help me how to do this programtically. Where to write the line so that i get this 3 name in my tabbar

推荐答案

尝试这种方式...

NSMutableArray *controllers = [[NSMutableArray alloc] init];
FirstViewController *obj_FirstViewController = [[FirstViewController alloc] init];
                [obj_FirstViewController setTitle:@"first"];
                UITabBarItem *item = [[[UITabBarItem alloc] setTabBarItem:          [[[UITabBarItem alloc] initWithTitle: @"First") image:[UIImage imageNamed:@"first.png"] tag:2] autorelease]];
                [obj_FirstViewController setTabBarItem:item];
                [controllers addObject:obj_FirstViewController];
                [obj_FirstViewController release];

这篇关于以编程方式设置UITabBar标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆