无法以编程方式在 Xcode 4.2 中设置标签栏图像 [英] Could not set tab bar image in Xcode 4.2 Programmatically

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

问题描述

我在 xcode 4.2 中创建了新的标签栏项目,但没有应用程序委托 xib 文件.项目有两个导航控制器.我可以设置标签栏的名称,但无法设置图像.我完全厌倦了很多尝试.FirstViewController *firstView = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil]

I created new tab bar project in xcode 4.2 and there is no app delegate xib file. Project has two navigation controller. I can set name of tab bar but couldn't set image. I am completely fed up with many tries. FirstViewController *firstView = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil]

firstView.title=@"Birthdays";
firstView.tabBarItem.image=[UIImage imageNamed:@"bottomleft.png"]; 
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil]; 
secondView.title=@"Settings"; 
secondView.tabBarItem.image=[UIImage imageNamed:@"bottomright.png"]; 
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondView];
    navController2.navigationBarHidden=YES;
    [viewControllers addObject:navController2];   

在这里你可以看到我得到什么样的输出.

Here you can see what sort of output I am getting.

推荐答案

从你发布的代码很难看出,但你可能想在 UINavigationController 的 tabBarItem 上设置图像 (navController2),因为它看起来是你直接添加到你的UITabBarController:

Hard to tell from the code you posted, but you probably want to set the image on the tabBarItem of the UINavigationController (navController2), since it looks like that is what you directly add to you UITabBarController:

navController2.tabBarItem.image = [UIImage imageNamed:@"bottomright.png"];

您可以设置标题的原因是导航控制器默认自动具有其当前子视图控制器的标题.

The reason you can set the title is that navigation controllers by default automatically have the title of their current child view controller.

这篇关于无法以编程方式在 Xcode 4.2 中设置标签栏图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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