新的iOS标签栏

时间:2012-01-11 20:07:04

标签: iphone ios ios5 tabbar

我最近回到原生iOS开发,正在开发Tab Bar应用程序。我注意到构建一个的过程已经改变了。所有教程都提到将Tab Bar控制器添加到基于Window的应用程序的mainwindow.xib中。我真的很喜欢使用界面构建器系统来创建一个标签栏,但这似乎已成为过去?

如果没有初始窗口添加标签栏控制器,它就是一个静音点。标签栏模板也不错,它只是使用代码来设置每个视图标签栏元素等。这很好,但我确实喜欢分离界面和背后的代码的方法。当我与客户合作时,很高兴向他们展示可视化的界面。

我的问题是1)是否可以使用标签栏控制器和界面构建来自定义标签栏? 2)我该怎么做呢?有没有教程?我并不反对使用空模板从头开始构建它。

谢谢,

大卫

1 个答案:

答案 0 :(得分:0)

您好,我认为本教程将为您提供帮助:

ios5定制中的

非常简单:

vistit:http://kurrytran.blogspot.com/2011/10/ios-5-tutorial-creating-custom-tab-bar.html

完成所有故事板,然后在viewdidload方法中设置所有内容。

- (void)viewDidLoad
{
    UIImage *selectedImage0 = [UIImage imageNamed:@"HomeDB.png"];
    UIImage *unselectedImage0 = [UIImage imageNamed:@"HomeLB.png"];

    UIImage *selectedImage1 = [UIImage imageNamed:@"ScheduleDB.png"];
    UIImage *unselectedImage1 = [UIImage imageNamed:@"ScheduleLB.png"];

    UIImage *selectedImage2 = [UIImage imageNamed:@"BuildingsDB.png"];
    UIImage *unselectedImage2 = [UIImage imageNamed:@"BuildingsLB.png"];

    UIImage *selectedImage3 = [UIImage imageNamed:@"InformationDB.png"];
    UIImage *unselectedImage3 = [UIImage imageNamed:@"InformationLB.png"];

    UIImage *selectedImage4 = [UIImage imageNamed:@"MoreDB.png"];
    UIImage *unselectedImage4 = [UIImage imageNamed:@"MoreLB.png"];

    UITabBar *tabBar = self.tabBarController.tabBar;
    UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
    UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
    UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
    UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
    UITabBarItem *item4 = [tabBar.items objectAtIndex:4];

    [item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
    [item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
    [item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
    [item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
    [item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];
    [super viewDidLoad];
         // Do any additional setup after loading the view, typically from a nib.
}

我希望它有所帮助。