我使用UITabBarController作为根视图,应用程序支持iOS 6及更高版本。项目类层次结构如下。
UITabBarController
- tab1
- UINavigationController
- UIViewController
- UIViewController
.
.
- tab2
- UINavigationController
- UIViewController
- UIViewController
.
.
.
- tab3
- UIViewController
- tab4
- UIViewController我使用下面的代码在上面的层次结构中的一个UIViewControllers (在UINavigationController中)中更改UITabBar的高度。
CGRect tabbarFrame = self.tabBarController.tabBar.frame;
tabbarFrame.size.height += 60;
self.tabBarController.tabBar.frame = tabbarFrame;但它不会改变高度。UITabBar以默认高度显示。尽管记录它的值会打印更改后的值,如下所示。
<UITabBar: 0xb528f60; frame = (0 431; 320 109); autoresize = W+TM; layer = <CALayer: 0xb529080>>如何更改UITabBar的高度以实现如下所示:?

发布于 2014-10-08 19:14:49
我面对了这个问题,并且我能够解决它。
您必须将以下代码添加到UITabBarController类的子类中。
const CGFloat kBarHeight = 80;
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
CGRect tabFrame = self.tabBar.frame; //self.TabBar is IBOutlet of your TabBar
tabFrame.size.height = kBarHeight;
tabFrame.origin.y = self.view.frame.size.height - kBarHeight;
self.tabBar.frame = tabFrame;
}Swift:
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
tabBar.frame.size.height = kBarHeight
tabBar.frame.origin.y = view.frame.height - kBarHeight
}发布于 2015-03-12 21:32:25
对于iOS 8.2,Xcode 6.2 Swift语言:
为你的UITabBarController (类型为UITabBarController)创建一个"DNMainTabVC.swift“(DeveloperNameMainTabViewController.swift文件),并将它连接到你的故事板VC。
添加以下行:
override func viewWillLayoutSubviews() {
var tabFrame = self.tabBar.frame
// - 40 is editable , the default value is 49 px, below lowers the tabbar and above increases the tab bar size
tabFrame.size.height = 40
tabFrame.origin.y = self.view.frame.size.height - 40
self.tabBar.frame = tabFrame
}这对我很有效。
发布于 2017-09-13 14:16:35
与 Swift 3.0、Swift 4.0兼容的
Pre-iPhone X默认选项卡栏高度:49pt
iPhone X默认选项卡栏高度:83pt
支持所有iOS设备(包括iPhone X screen size )的通用解决方案如下所示:
fileprivate lazy var defaultTabBarHeight ={ tabBar.frame.size.height }()
重写函数viewWillLayoutSubviews() { super.viewWillLayoutSubviews() let newTabBarHeight = defaultTabBarHeight +16.0var newFrame = tabBar.frame newFrame.size.height = newTabBarHeight newFrame.origin.y = view.frame.size.height - newTabBarHeight tabBar.frame = newFrame }
https://stackoverflow.com/questions/23044218
复制相似问题