iPhone Programmatically
iPhone Programmatically

Reputation: 1227

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.

Upvotes: 0

Views: 375

Answers (2)

Abdullah Umer
Abdullah Umer

Reputation: 4644

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.

Upvotes: 1

Mansi Panchal
Mansi Panchal

Reputation: 2357

Tabbar controller has its own property of Image and Title.

Go through this UITabbar Tutorial to understand properly. You can set image through property window or even through coding also.

Best Luck !

Upvotes: 1

Related Questions