How to set individual tabbaritem icons in uitabbarcontroller in cocoa

I was told how to set images in general for the uitabbarcontroller. however, my uitabbarcontroller is an array of views that looks like this:

tabBarController = [[UITabBarController alloc] init]; viewTab1controller = [[ViewTab1Controller alloc] initWithNibName:@"ViewTab1" bundle:nil]; viewTab1controller.title = @"Schedules"; navigationTab1Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab1controller] autorelease]; [viewTab1controller release]; viewTab2controller = [[ViewTab2Controller alloc] initWithNibName:@"ViewTab2" bundle:nil]; viewTab2controller.title = @"Nearest Stop"; navigationTab2Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab2controller] autorelease]; [viewTab2controller release]; viewTab3controller = [[ViewTab3Controller alloc] initWithNibName:@"ViewTab3" bundle:nil]; viewTab3controller.title = @"Routes"; navigationTab3Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab3controller] autorelease]; [viewTab3controller release]; viewTab4controller = [[ViewTab4Controller alloc] initWithNibName:@"ViewTab4" bundle:nil]; viewTab4controller.title = @"Feedback"; navigationTab4Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab4controller] autorelease]; [viewTab4controller release]; //viewTab5controller = [[ViewTab5Controller alloc] initWithNibName:@"ViewTab5" bundle:nil]; //navigationTab5Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab5controller] autorelease]; //[viewTab5controller release]; tabBarController.viewControllers = [NSArray arrayWithObjects: navigationTab1Controller, navigationTab2Controller, navigationTab3Controller, navigationTab4Controller, //navigationTab5Controller, 

I was provided with the code in the previous answer to add an image to tabbaritem:

  viewController.tabBarItem.image = [UIImage imageNamed:@"foo.png"]; 

However, this does not indicate a specific tabbbaritem.

How to assign an image to each of these 4 tabs?

Thanks! zero];

+4
source share
1 answer

Do this for each view controller that you add to the tab bar:

 viewTab1controller = [[ViewTab1Controller alloc] initWithNibName:@"ViewTab1" bundle:nil]; viewTab1controller.title = @"Schedules"; navigationTab1Controller = [[UINavigationController alloc] initWithRootViewController:viewTab1controller]; navigationTab1Controller.tabBarItem.image = [UIImage imageNamed:@"Match.png"]; 
+17
source

Source: https://habr.com/ru/post/1286037/


All Articles