views:

1412

answers:

2

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?

+5  A: 

UIViewController has a tabBarItem property which has an image property (inherited from the UIBarItem class UITabBarItem subclasses). For example:

viewController.tabBarItem.image = [UIImage imageNamed:@"foo.png"];
Martin Gordon
my tabbarcontroller is an array of uiviews how do i know which is which tabbaritem?
Buffernet
it seems that the .image property of UITabBarItem is undocumented... are you sure we are supposed to use that property?
Johnus
+1  A: 

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"];
Buffernet