自定义UITabBar和ViewController之间的空间

Nad*_*rbn 6 iphone objective-c uitabbarcontroller uitabbar ios

我经常UITabBar把它的背景图像改成了一个高度较低的自定义图像,所以我更改了heightframe.我首先得到的是标签栏下方的空白区域.所以我改变了originframe了.但是现在空白区域已经向上移动到标签栏上方,这就是结果:

标签栏上方的空间

这是在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;
Run Code Online (Sandbox Code Playgroud)

我想问题是,ViewControllers将自己绘制在一个恒定空间之上,这是常规标签栏的高度.有没有办法改变它?

Sid*_*Koh 7

将您的UITabBarController的子视图更改为一个完整大小的框架,这对我有用:

[[yourTabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 480)];
Run Code Online (Sandbox Code Playgroud)


cri*_*ega 7

尝试创建从UITabBar扩展的类,并使用此函数:

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

这会将UITabBar调整到您想要的大小.简单易行.