Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Space between custom UITabBar and ViewController

I took a regular UITabBar and changed it's background image to a custom one which has a lower height, so I changed the height of the frame. At first what I got is a blank space below the tab bar. so I changed the origin of the frame too. But now the blank space has moved up above the tab bar and this is the result:

space above tab bar

And this is the code declaring the tab bar in the AppDelegate:

self.tabContoller = [[UITabBarController alloc] init];
//customizing the tabbar
UIImage * tabBackgroundImage = [UIImage imageNamed:@"tabBarBg.png"];
self.tabContoller.tabBar.backgroundColor = [UIColor colorWithRed:245.f/255.f green:245.f/255.f blue:245.f/255.f alpha:255.f/255.f];
self.tabContoller.tabBar.backgroundImage = tabBackgroundImage;
//setting the tabbar height to the correct height of the image
CGRect tabR = self.tabContoller.tabBar.frame;
CGFloat diff = tabR.size.height - tabBackgroundImage.size.height;
tabR.size.height = tabBackgroundImage.size.height;
tabR.origin.y += diff;
self.tabContoller.tabBar.frame = tabR;

I guess that the problem is that the ViewControllers draw themselves above a constant space which is the height of the regular tab bar. Is there any way to change it?

like image 887
Nadavrbn Avatar asked May 24 '12 12:05

Nadavrbn


2 Answers

Change your UITabBarController's subviews to a full-sized frame, this worked for me:

[[yourTabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 480)];
like image 146
Sidwyn Koh Avatar answered Nov 07 '22 12:11

Sidwyn Koh


Try creating your own class extending from UITabBar and use this function:

- (CGSize)sizeThatFits:(CGSize)size {
    CGSize auxSize = size;
    auxSize.height = 54; // Put here the new height you want and that's it
    return auxSize;
}

This will resize the UITabBar to the size you want. Simple and easy.

like image 7
crisisGriega Avatar answered Nov 07 '22 11:11

crisisGriega