UITabBar height setting

I created a simple custom tab by setting the images of each element as follows:

UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];

[item0 setFinishedSelectedImage:[UIImage imageNamed:@"activity_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"activity.png"]];
[item1 setFinishedSelectedImage:[UIImage imageNamed:@"agenda_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"agenda.png"]];
[item2 setFinishedSelectedImage:[UIImage imageNamed:@"settings_active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"settings.png"]];

While this works great, I noticed that there is a black blank space in my tab

enter image description here

My images are 44 pixels tall, but I think I need to somehow change the height of my tab.

+5
source share
3 answers

The tabBar itself is 49px, and it is displayed in black behind your images (possibly in [UITabBar layoutSubviews]). Then your images are displayed on top. The reason for the bias is because the images you supply are too large, the UITabBar expects 30x30px icons, not the images of the entire UITabBarItem.

Here are some things you can try:

  • 30x30px,
  • , , : [item setImageInsets:UIEdgeInsetsMake(6, 0, -6, 0)]; // play with insets until it renders correctly
  • UITabBar layoutSubviews super, . , iOS.
+2

-

tabBar.frame=CGRectMake(x,y,w,h);

xCord, yCord, .

0

Check this:

[self.tabBar setFrame:CGRectMake(self.tabBar.frame.origin.x, self.tabBar.frame.origin.y - 30, self.tabBar.frame.size.width, self.tabBar.frame.size.height + 30)];
0
source

All Articles