Add image to UITabBar

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

0


source to share


1 answer


you can add them to the appDidFinishLaunching: function in the appDelegate.m file.

eg:



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

      

+3


source







All Articles