Thursday, May 5, 2011

Add a picture to UITabBar

Hi,

I have view controllers added to my UITabBarController in the interface builder. How can I add a picture and change item title programmatically?

From stackoverflow
  • Hi,

    you can add them at 'applicationDidFinishLaunching:' function in appDelegate.m file.

    for example :

    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 ++;
    }
    

0 comments:

Post a Comment