无法在Xcode 4.2中设置标签栏图像编程
我在xcode 4.2中创建了新的标签栏项目,并且没有应用程序委托xib文件。项目有两个导航控制器。我可以设置标签栏的名称,但无法设置图像。我完全厌倦了很多尝试。 FirstViewController *firstView = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil]
无法在Xcode 4.2中设置标签栏图像编程
[email protected]"Birthdays";
firstView.tabBarItem.image=[UIImage imageNamed:@"bottomleft.png"];
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil];
[email protected]"Settings";
secondView.tabBarItem.image=[UIImage imageNamed:@"bottomright.png"];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondView];
navController2.navigationBarHidden=YES;
[viewControllers addObject:navController2];
在这里你可以看到我得到什么样的输出。
很难从您发布的代码中分辨出来,但您可能想要等上UINavigationController
(navController2
)的tabBarItem
的图像,因为它看起来像这就是你直接添加到您UITabBarController
:
navController2.tabBarItem.image = [UIImage imageNamed:@"bottomright.png"];
您可以设置标题的原因是默认的导航控制器会自动有他们当前的子视图控制器的标题。
你永远需要做到这一点:
[UIImage imageNamed:@"bottomleft2x.png"];
UIImage
会自动判断@2x
是否需要或不基于屏幕比例,所以要简单说:
[UIImage imageNamed:@"bottomleft.png"];
除非,当然,您的资源名称实际上是[email protected]
看起来您已成功替换左侧图像,但它没有透明区域。您是否遵循了设计选项卡图标的指导原则?
您需要在透明背景上使用白色图像。如果您的背景不透明,则整个图像将只是一个蓝色框,就像您左侧标签上的那个。
示例:要制作带有星形的选项卡,请在透明背景上绘制完全白色的星形。不要使用除完全白色和透明黑色之外的其他颜色。
这是您的问题。我在这里找到了一个非常直接的教程:http://greenerpastures.dk/blog/iphone-udvikling/how-to-make-tab-bar-icons – ravron 2012-07-12 03:06:13
哥们标签栏只允许白色和透明背景,所以如果你想让图片像生日蛋糕,然后在透明的背景上画一个白色的生日蛋糕,然后在蛋糕上添加一些透明像素来创建外观一个蛋糕,而不是只是蛋糕的轮廓,然后你可以设置年图像标签栏
Coneybeare,我也做了同样的事情,但仍然得到相同的结果。你可以在我的答案中看到图像。 – josh 2012-07-08 17:56:38
有时xcode无法将文件添加到项目中,可能需要手动删除并再次添加到xcode – 2012-07-09 06:50:02