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?
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"];
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"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With