代码之家  ›  专栏  ›  技术社区  ›  Ilya Suzdalnitski

将图片添加到Uitabar

  •  0
  • Ilya Suzdalnitski  · 技术社区  · 15 年前

    我在界面生成器中将视图控制器添加到我的UITabbarController中。如何以编程方式添加图片和更改项目标题?

    1 回复  |  直到 15 年前
        1
  •  3
  •   xenep    15 年前

    您可以在appdelegate.m文件中的“applicationDidFinishLaunching:”函数中添加它们。

    例如:

    NSInteger index = 0;
    while(index < 4){ // 4 is the number of tabbar items
        UINavigationController *navCtrlr = (UINavigationController*)[[tabBarController viewControllers] objectAtIndex:index];
        UITabBarItem *tabBar = (UITabBarItem *) navCtrlr.tabBarItem;
        if(index == 0){
            tabBar.image = [UIImage imageNamed:@"home-item.png"];
            tabBar.title = @"home";
        }
        ...
        index ++;
    }