2012-03-25 99 views
-1

我已经在我的应用程序委托中实现了标签栏控制器,但它只是标签栏中的空白方块。我希望能够改变它们的标题和图像,并且我想知道如何不仅使用我添加的自定义图像,而且使用在Xcode中实现的“默认”图像(“计算器”图像,“搜索”图像)。更改标签栏项目标题和颜色programmaticaly

如果您在xib中有标签栏,您可以在标签栏项目 - >属性检查器 - >标识符中看到它,如果您不想使用自定义图像,则会出现一个列表。所以我appDelegate.m代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after app launch 


    UIViewController *banksList = [[FailedBanksListViewController alloc] initWithNibName:@"FailedBanksListViewController" bundle:nil]; 
    UINavigationController *listNavigationController = [[UINavigationController alloc] initWithRootViewController:banksList]; 

    UIViewController *first = [[BIDViewController alloc] initWithNibName:@"BIDViewController" bundle:nil];  
    UIViewController *second = [[BIDDailyCount alloc] initWithNibName:@"BIDDailyCount" bundle:nil]; 

    self.tabBarController = [[UITabBarController alloc] init]; 
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:first,second,listNavigationController, nil]; 
    self.window.rootViewController = self.tabBarController; 
    [self.window makeKeyAndVisible];  


    return YES; 
} 

回答

2

你必须创建UITabBarItem是你的自我。

在你的appdelegate,你可以这样做:

UIViewController *banksList = [[FailedBanksListViewController alloc] initWithNibName:@"FailedBanksListViewController" bundle:nil]; 
banksList.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:0]; 

回归自我;

将它移动到每个选项卡的控制器中的自定义初始化程序可能是一个好主意。

+0

谢谢Jacob,它有帮助! – Necrosoft 2012-03-25 08:10:50

+0

系统'UITabBarSystemItemSearch' *是图像。我以为那是你想要的。你像通常那样设置标题:'banksList.title = @“List”;' – 2012-03-25 08:15:11

+0

问题解决了。再次感谢! – Necrosoft 2012-03-25 08:31:20