I have solved just the same problem it this way:
my goal was to customize tab bar by using images, that were sent by the designer for me.
I have attached the .png files for the project, initialized the correspondent variables of type UIImage* and used UITabBarItem function setFinishedSelectedImage: withFinishedUnselectedImage: to set the images for active / inactive state of UITabbarItem:
UIImage * left_active, *left_inactive, *center_active, *center_inactive, *right_active, *right_inactive;
left_active = [UIImage imageNamed:@"left_active_img"];
...
[self.leftTabBarItem setFinishedSelectedImage:left_active withFinishedUnselectedImage:left_inactive];
[self.centerTabBarItem setFinishedSelectedImage:center_active withFinishedUnselectedImage:center_inactive];
[self.rightTabBarItem setFinishedSelectedImage:right_active withFinishedUnselectedImage:right_inactive];
But the customized tabbarItems were smaller, than the designer's images and were allocated at the center of the screen one upon other:
2) To fix this I have ADDED ADDITIONAL UITABBARITEMS - at the left and at the right corner of the initial ones
3) the were created the correspondent outlets for the UITabBarItems:
.h-file:
@property (nonatomic, retain) IBOutlet UITabBar * tabBar;
// THE INTIAL items
@property (nonatomic, retain) IBOutlet UITabBarItem * leftTabBarItem;
@property (nonatomic, retain) IBOutlet UITabBarItem * centerTabBarItem;
@property (nonatomic, retain) IBOutlet UITabBarItem * rightTabBarItem;
// THE ADDITIONAL items
@property (nonatomic, retain) IBOutlet UITabBarItem * left_1;
@property (nonatomic, retain) IBOutlet UITabBarItem * left_2;
@property (nonatomic, retain) IBOutlet UITabBarItem * center_1;
@property (nonatomic, retain) IBOutlet UITabBarItem * center_2;
@property (nonatomic, retain) IBOutlet UITabBarItem * right_1;
@property (nonatomic, retain) IBOutlet UITabBarItem * right_2;
then attached the Outlets to the UITabBarItems in the order listed below:
- left_1
- leftTabBarItem
- left_2
- center_1
- centerTabBarItem
- center_2
- right_1
- rightTabBarItem
- right_2
and CORRECTED THE UITabbarDelegate METHOD in the delegating class to switch ONLY beet wen the visible items
.m-file:
#pragma mark - UITabbarDelegate
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
if (item == self.leftTabBarItem)
{
NSLog(@"0"); // first visible item selected
} else if (item == self.centerTabBarItem)
{
NSLog(@"1"); // second visible item selected
} else if (item == self.rightTabBarItem)
{
NSLog(@"2"); // third visible item selected
} else if (item == self.left_1){
[self.tabBar setSelectedItem: self.leftTabBarItem];
} else if (item == self.left_2){
[self.tabBar setSelectedItem: self.leftTabBarItem];
} else if (item == self.center_1){
[self.tabBar setSelectedItem: self.centerTabBarItem];
}else if (item == self.center_2){
[self.tabBar setSelectedItem: self.centerTabBarItem];
}else if (item == self.right_1){
[self.tabBar setSelectedItem: self.rightTabBarItem];
} else if (item == self.right_2){
[self.tabBar setSelectedItem: self.rightTabBarItem];
}
}
Now everything looks and works properly.
You can use the same steps to customize the size and interspaces between UITabBarItems by adding additional items and correcting delegate methods.