Search code examples
iphoneuitabbarcontrolleruitabbar

Setting image on tabbar items in special case(if tab bar taken on viewController)


I am taking tab bar controller on view controller rather than delegate, and used code what mentioned below.

tabController = [[UITabBarController alloc]init];
tabController.delegate = self;

scanView = [[ScanTicketView alloc] init];
searchView = [[SearchView alloc] init];
historyView = [[HistoryView alloc]init];

tabController.viewControllers=[NSArray arrayWithObjects:scanView,searchView,historyView, nil];

[self.navigationController pushViewController:tabController animated:YES];

It works, but now how to apply images to these views. Can anyone help me here.

Thanks in advance.


Solution

  • You can use:

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

    if you want to apply the image only to selected view controller in Tab bar, then UITabBarController has a selectedViewController and a selectedIndex property also see tabBarController.tabBar.selectedItem.tag if this may help.