Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 349
Atma Avatar asked Jun 10 '09 20:06

Atma


2 Answers

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"];
like image 194
Atma Avatar answered Nov 07 '22 12:11

Atma


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"];
like image 28
Martin Gordon Avatar answered Nov 07 '22 11:11

Martin Gordon