Space between custom UITabBar and ViewController

别说谁变了你拦得住时间么 提交于 2019-12-21 02:35:12

问题


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:

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?


回答1:


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)];



回答2:


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.




回答3:


If changing the frame like @JoaT mentioned doesn't work make sure the view controller's view has the correct autoresizing mask set.

This SO link may be helpful.




回答4:


I tried by changing the height and origin of tabbar, for me it worked properly.You can try by increasing the height of your viewcontroller.



来源:https://stackoverflow.com/questions/10737420/space-between-custom-uitabbar-and-viewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!