Search code examples
cocoa-touchimageuitabbarcontroller

how to set image for uitabbarcontroller in cocoa code


Hi I am creating a tab bar controller in xcode and not in interface builder. the titles of the views in the tabs set the titles in the tabs but I'm unsure how to set images.

Can anyone help?


Solution

  • I figured it out you can get the array of view controllers and then add the images:

               NSArray *tabs =  tabBarController.viewControllers;
    UIViewController *tab1 = [tabs objectAtIndex:0];
    tab1.tabBarItem.image = [UIImage imageNamed:@"clockicon.png"];
    UIViewController *tab2 = [tabs objectAtIndex:1];
    tab2.tabBarItem.image = [UIImage imageNamed:@"nearest.png"];