自定义UITabBar和ViewController之间的空间
我采取了一个普通的UITabBar
,并将其背景图像更改为一个具有较低高度的自定义的,所以我改变了frame
的height
。 起初我得到的是标签栏下方的空白处。 所以我也改变了frame
的origin
。 但是现在空格已经移到标签栏之上了,结果是:
这是在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;
我想问题是, ViewController
绘制自己的常量标签栏的高度不变的空间之上。 有什么方法可以改变它吗?
改变你的UITabBarController的子视图到一个全尺寸的框架,这对我工作:
[[yourTabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 480)];
尝试创build自己的类从UITabBar扩展和使用此function:
- (CGSize)sizeThatFits:(CGSize)size { CGSize auxSize = size; auxSize.height = 54; // Put here the new height you want and that's it return auxSize; }
这将调整UITabBar到你想要的大小。 简单和容易。
如果像提到的@JoaT那样改变框架不起作用,请确保视图控制器的视图具有正确的自动识别掩码集。
这个SO链接可能会有所帮助。
我试图通过改变tabbar的高度和起源,对我来说它工作正常。你可以尝试通过增加你的viewcontroller的高度。