我使用 UITabBarController
作为 Root View ,应用支持 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
的高度来达到这样的效果:?
最佳答案
我遇到了这个问题,我能够解决它。
您必须将以下代码添加到 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
}
https://stackoverflow.com/questions/23044218/
相关文章:
ios - UICollectionView:如何检测滚动何时停止
objective-c - 100% 不透明度 UILabel 超过 50% 不透明度背景(UIVi
iphone - 选中时选中的 UItableViewCell 保持蓝色
iphone - 如何在当前 UITableViewController 上方添加一个 UIView
iphone - 在 UITableView 的 iOS 文档目录中列出保存的文件?
ios - performFetchWithCompletionHandler 永远不会被解雇
ios - 根据文本量更改 UITableViewCell 高度
iphone - 在 bundle 中找不到名为 'Main' 的 Storyboard