Reputation: 1568
I am trying to create a UITabBar that I will customize using the appearance API. I am stuck on trying to remove the title label from the UITabBarItem and resizing the image to make it centered. If you just delete the title text, there will be empty space below the image and the bottom of the bar.
Does anyone know how to make a UITabBarItem without a title?
Upvotes: 7
Views: 6819
Reputation: 6263
Set the title to nil
and move the icon
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil
image:[[UIImage imageNamed:@"icon_tabbar_inactive.png"]
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
selectedImage:[[UIImage imageNamed:@"icon_tabbar_active.png"]
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
// Move the tabbar icon to the middle of tabbar
self.tabBarItem.imageInsets = UIEdgeInsetsMake(6.0, 0.0, -6.0, 0.0);
Upvotes: 11
Reputation: 1
My solution for the same problem:
1, make the bar origin y lower, push the empty space outside the screen.
2, reset the background to ensure it just cover the right position.
Upvotes: 0
Reputation: 2974
made same task just today.
Since I can't use full space of tab bar for item image I just change tab bar background when user press any tab.
So the first step is to prepare background images with full size buttons for every tab selected.
Then create custom class and assign it for your tab bar controller
In your custom class set background image for first tab in ViewDidLoad:
[[self tabBar] setBackgroundImage:[UIImage imageNamed:@"tabShopsActive"]];
[[self tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"tabSelection"]];
Add background change for every UIController in ViewWillAppear:
UITabBarController *bar = [self tabBarController];
[bar.tabBar setBackgroundImage:[UIImage imageNamed:@"tabDiscountsActive"]];
So now when user press any tab Tab Bar change background to show correct picture for it.
It is my resulting tab bar when second tab selected:
Upvotes: 7